@sentio/sdk 2.9.0-rc.3 → 2.9.0-rc.5
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 +14 -2
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +6 -6
- package/lib/aptos/aptos-processor.js +4 -4
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/context.d.ts +1 -1
- package/lib/aptos/context.js +1 -1
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.d.ts +2 -2
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/aptos/index.d.ts +2 -2
- package/lib/aptos/index.js +2 -2
- package/lib/aptos/index.js.map +1 -1
- package/lib/eth/index.d.ts +1 -0
- package/lib/eth/index.js +1 -0
- package/lib/eth/index.js.map +1 -1
- package/lib/sui/context.d.ts +1 -1
- package/lib/sui/context.js +1 -1
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/sui-plugin.js +3 -1
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +13 -8
- package/lib/sui/sui-processor.js +16 -9
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/aptos-plugin.ts +17 -3
- package/src/aptos/aptos-processor.ts +9 -9
- package/src/aptos/context.ts +1 -1
- package/src/aptos/ext/aptos-dex.ts +2 -2
- package/src/aptos/index.ts +2 -2
- package/src/eth/index.ts +1 -0
- package/src/sui/context.ts +1 -1
- package/src/sui/sui-plugin.ts +3 -1
- package/src/sui/sui-processor.ts +33 -15
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
import { AccountConfig, ContractConfig, HandlerType, } from '@sentio/protos';
|
1
|
+
import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime';
|
2
|
+
import { AccountConfig, ContractConfig, HandlerType, MoveOnIntervalConfig_OwnerType, } from '@sentio/protos';
|
3
3
|
import { ServerError, Status } from 'nice-grpc';
|
4
4
|
import { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js';
|
5
5
|
import { initCoinList } from './ext/coin.js';
|
@@ -65,6 +65,7 @@ export class AptosPlugin extends Plugin {
|
|
65
65
|
});
|
66
66
|
for (const handler of aptosProcessor.resourcesHandlers) {
|
67
67
|
const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1;
|
68
|
+
// TODO move to only use moveIntervalConfigs
|
68
69
|
accountConfig.aptosIntervalConfigs.push({
|
69
70
|
intervalConfig: {
|
70
71
|
handlerId: handlerId,
|
@@ -75,6 +76,17 @@ export class AptosPlugin extends Plugin {
|
|
75
76
|
},
|
76
77
|
type: handler.type || '',
|
77
78
|
});
|
79
|
+
accountConfig.moveIntervalConfigs.push({
|
80
|
+
intervalConfig: {
|
81
|
+
handlerId: handlerId,
|
82
|
+
minutes: 0,
|
83
|
+
minutesInterval: handler.timeIntervalInMinutes,
|
84
|
+
slot: 0,
|
85
|
+
slotInterval: handler.versionInterval,
|
86
|
+
},
|
87
|
+
type: handler.type || '',
|
88
|
+
ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,
|
89
|
+
});
|
78
90
|
}
|
79
91
|
config.accountConfigs.push(accountConfig);
|
80
92
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EAGb,cAAc,EAKd,WAAW,GAIZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA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C,wBAAwB,CAAC,OAAoB;QACjD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE;YAC1B,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,CAAA;SACtE;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAA;QAEjC,MAAM,QAAQ,GAA6B,EAAE,CAAA;QAC7C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE;YAC1C,kCAAkC;YAClC,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAClE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;YAClH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACvB;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'\n\nimport { initCoinList } from './ext/coin.js'\n\nexport class AptosPlugin extends Plugin {\n name: string = 'AptosPlugin'\n\n private aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[] = []\n private aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[] = []\n private aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[] = []\n\n async start(start: StartRequest) {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: aptosProcessor.config.address,\n abi: '',\n },\n startBlock: aptosProcessor.config.startVersion,\n })\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = this.aptosEventHandlers.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\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = this.aptosCallHandlers.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 aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: aptosProcessor.config.address,\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n })\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n type: handler.type || '',\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.APT_CALL:\n return this.processAptosFunctionCall(request)\n case HandlerType.APT_EVENT:\n return this.processAptosEvent(request)\n case HandlerType.APT_RESOURCE:\n return this.processAptosResource(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.aptEvent\n\n for (const handlerId of binding.handlerIds) {\n // only support aptos event for now\n promises.push(\n this.aptosEventHandlers[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 processAptosResource(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptResource) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Resource can't be empty\")\n }\n const resource = binding.data.aptResource\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.aptosResourceHandlers[handlerId](resource).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing resource: ' + JSON.stringify(resource) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.aptCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n // only support aptos call for now\n const promise = this.aptosCallHandlers[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\nPluginManager.INSTANCE.register(new AptosPlugin())\n"]}
|
1
|
+
{"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-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,EAMX,8BAA8B,GAC/B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,MAAM,OAAO,WAAY,SAAQ,MAAM;IACrC,IAAI,GAAW,aAAa,CAAA;IAEpB,kBAAkB,GAAyD,EAAE,CAAA;IAC7E,iBAAiB,GAAuD,EAAE,CAAA;IAC1E,qBAAqB,GAA0E,EAAE,CAAA;IAEzG,KAAK,CAAC,KAAK,CAAC,KAAmB;QAC7B,MAAM,YAAY,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,KAAK,MAAM,cAAc,IAAI,mBAAmB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACrE,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;gBAChD,aAAa,EAAE,cA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B,CAAC,CAAA;SACtE;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAA;QAEjC,MAAM,QAAQ,GAA6B,EAAE,CAAA;QAC7C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE;YAC1C,kCAAkC;YAClC,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAClE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;YAClH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACvB;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n MoveOnIntervalConfig_OwnerType,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'\n\nimport { initCoinList } from './ext/coin.js'\n\nexport class AptosPlugin extends Plugin {\n name: string = 'AptosPlugin'\n\n private aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[] = []\n private aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[] = []\n private aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[] = []\n\n async start(start: StartRequest) {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: aptosProcessor.config.address,\n abi: '',\n },\n startBlock: aptosProcessor.config.startVersion,\n })\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = this.aptosEventHandlers.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\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = this.aptosCallHandlers.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 aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: aptosProcessor.config.address,\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n })\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1\n // TODO move to only use moveIntervalConfigs\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n type: handler.type || '',\n })\n\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n type: handler.type || '',\n ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n async processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.APT_CALL:\n return this.processAptosFunctionCall(request)\n case HandlerType.APT_EVENT:\n return this.processAptosEvent(request)\n case HandlerType.APT_RESOURCE:\n return this.processAptosResource(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.aptEvent\n\n for (const handlerId of binding.handlerIds) {\n // only support aptos event for now\n promises.push(\n this.aptosEventHandlers[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 processAptosResource(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptResource) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Resource can't be empty\")\n }\n const resource = binding.data.aptResource\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.aptosResourceHandlers[handlerId](resource).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing resource: ' + JSON.stringify(resource) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.aptCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.aptCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n // only support aptos call for now\n const promise = this.aptosCallHandlers[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\nPluginManager.INSTANCE.register(new AptosPlugin())\n"]}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js';
|
2
2
|
import { MoveCoder } from './move-coder.js';
|
3
3
|
import { AptosBindOptions, AptosNetwork } from './network.js';
|
4
|
-
import { AptosContext,
|
4
|
+
import { AptosContext, AptosResourcesContext } from './context.js';
|
5
5
|
import { EventInstance } from './models.js';
|
6
6
|
import { ListStateStorage } from '@sentio/runtime';
|
7
7
|
import { MoveFetchConfig, Data_AptResource, HandleInterval, ProcessResult, Data_AptEvent, Data_AptCall } from '@sentio/protos';
|
@@ -33,17 +33,17 @@ export declare class AptosBaseProcessor {
|
|
33
33
|
loadTypes(registry: MoveCoder): void;
|
34
34
|
protected loadTypesInternal(registry: MoveCoder): void;
|
35
35
|
}
|
36
|
-
export declare class AptosAccountProcessorState extends ListStateStorage<
|
36
|
+
export declare class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {
|
37
37
|
static INSTANCE: AptosAccountProcessorState;
|
38
38
|
}
|
39
|
-
export declare class
|
39
|
+
export declare class AptosResourcesProcessor {
|
40
40
|
config: IndexConfigure;
|
41
41
|
resourcesHandlers: ResourceHandlder[];
|
42
|
-
static bind(options: AptosBindOptions):
|
42
|
+
static bind(options: AptosBindOptions): AptosResourcesProcessor;
|
43
43
|
protected constructor(options: AptosBindOptions);
|
44
44
|
getChainId(): string;
|
45
45
|
private onInterval;
|
46
|
-
onTimeInterval(handler: (resources: MoveResource[], ctx:
|
47
|
-
onVersionInterval(handler: (resources: MoveResource[], ctx:
|
46
|
+
onTimeInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string): this;
|
47
|
+
onVersionInterval(handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void, versionInterval?: number, backfillVersionInterval?: number, typePrefix?: string): this;
|
48
48
|
}
|
49
49
|
export {};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { MOVE_CODER } from './move-coder.js';
|
2
2
|
import { AptosNetwork, getChainId } from './network.js';
|
3
|
-
import { AptosContext,
|
3
|
+
import { AptosContext, AptosResourcesContext } from './context.js';
|
4
4
|
import { ListStateStorage } from '@sentio/runtime';
|
5
5
|
import { MoveFetchConfig, } from '@sentio/protos';
|
6
6
|
import { ServerError, Status } from 'nice-grpc';
|
@@ -131,11 +131,11 @@ export class AptosBaseProcessor {
|
|
131
131
|
export class AptosAccountProcessorState extends ListStateStorage {
|
132
132
|
static INSTANCE = new AptosAccountProcessorState();
|
133
133
|
}
|
134
|
-
export class
|
134
|
+
export class AptosResourcesProcessor {
|
135
135
|
config;
|
136
136
|
resourcesHandlers = [];
|
137
137
|
static bind(options) {
|
138
|
-
return new
|
138
|
+
return new AptosResourcesProcessor(options);
|
139
139
|
}
|
140
140
|
constructor(options) {
|
141
141
|
this.config = configure(options);
|
@@ -152,7 +152,7 @@ export class AptosAccountProcessor {
|
|
152
152
|
throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large');
|
153
153
|
}
|
154
154
|
const timestamp = Number(data.timestampMicros);
|
155
|
-
const ctx = new
|
155
|
+
const ctx = new AptosResourcesContext(processor.config.network, processor.config.address, data.version, timestamp);
|
156
156
|
await handler(data.resources, ctx);
|
157
157
|
return ctx.getProcessResult();
|
158
158
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAa,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAoB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,eAAe,GAMhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAU/C,MAAM,gBAAgB;IACpB,IAAI,CAAS;IACb,eAAe,CAAiB;IAChC,qBAAqB,CAAiB;IACtC,OAAO,CAAwD;CAChE;AAED,MAAM,OAAO,mBAAoB,SAAQ,gBAAoC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,mBAAmB,EAAE,CAAA;;AAG7C,MAAM,OAAO,kBAAkB;IACpB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IACtB,aAAa,GAAkC,EAAE,CAAA;IACjD,YAAY,GAAgC,EAAE,CAAA;IAE9C,YAAY,UAAkB,EAAE,OAAyB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;QAChC,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC3C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IAC5B,CAAC;IAED,qCAAqC;IACrC,qBAAqB;IACrB,IAAI;IAEG,aAAa,CAClB,OAA8E,EAC9E,cAAc,GAAG,KAAK,EACtB,WAA6B;QAE7B,MAAM,YAAY,GAAG,WAAW,IAAI,eAAe,CAAC,WAA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I,YAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nimport { MOVE_CODER, MoveCoder } from './move-coder.js'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network.js'\nimport { AptosContext, AptosResourceContext } from './context.js'\nimport { EventInstance } from './models.js'\nimport { ListStateStorage } from '@sentio/runtime'\nimport {\n MoveFetchConfig,\n Data_AptResource,\n HandleInterval,\n ProcessResult,\n Data_AptEvent,\n Data_AptCall,\n} from '@sentio/protos'\nimport { ServerError, Status } from 'nice-grpc'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_AptResource) => Promise<ProcessResult>\n}\n\nexport class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {\n static INSTANCE = new AptosProcessorState()\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler<Data_AptEvent>[] = []\n callHandlers: CallHandler<Data_AptCall>[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n AptosProcessorState.INSTANCE.addValue(this)\n this.loadTypes(MOVE_CODER)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void,\n includedFailed = false,\n fetchConfig?: MoveFetchConfig\n ): this {\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\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 call = data.transaction as Transaction_UserTransaction\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(data.transaction.version),\n call\n )\n await handler(call, ctx)\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onMoveEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: MoveFetchConfig\n ): this {\n let _filters: EventFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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\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 Transaction_UserTransaction\n if (!txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn\n )\n\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const eventInstance = evt as EventInstance\n const decoded = MOVE_CODER.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: MoveFetchConfig\n ): this {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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\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 Transaction_UserTransaction\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = MOVE_CODER.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: MoveCoder) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: MoveCoder) {\n // should be override by subclass\n console.log('')\n }\n}\n\nexport class AptosAccountProcessorState extends ListStateStorage<AptosAccountProcessor> {\n static INSTANCE = new AptosAccountProcessorState()\n}\n\nexport class AptosAccountProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosAccountProcessor {\n return new AptosAccountProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n AptosAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (data) {\n if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n const timestamp = Number(data.timestampMicros)\n\n const ctx = new AptosResourceContext(\n processor.config.network,\n processor.config.address,\n data.version,\n timestamp\n )\n await handler(data.resources as MoveResource[], ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type: type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\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 onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,\n versionInterval = 100000,\n backfillVersionInterval = 400000,\n typePrefix?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },\n typePrefix\n )\n }\n}\n\nfunction configure(options: AptosBindOptions): IndexConfigure {\n let startVersion = 0n\n if (options.startVersion !== undefined) {\n if (typeof options.startVersion === 'number') {\n startVersion = BigInt(options.startVersion)\n } else {\n startVersion = options.startVersion\n }\n }\n\n return {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAa,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAoB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,eAAe,GAMhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAU/C,MAAM,gBAAgB;IACpB,IAAI,CAAS;IACb,eAAe,CAAiB;IAChC,qBAAqB,CAAiB;IACtC,OAAO,CAAwD;CAChE;AAED,MAAM,OAAO,mBAAoB,SAAQ,gBAAoC;IAC3E,MAAM,CAAC,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,GAAG,MAAM,EAChC,UAAmB;QAEnB,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,SAAS,EACT,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,EAC9E,UAAU,CACX,CAAA;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAI,YAAY,GAAG,EAAE,CAAA;IACrB,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;QACtC,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;YAC5C,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;SAC5C;aAAM;YACL,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;SACpC;KACF;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nimport { MOVE_CODER, MoveCoder } from './move-coder.js'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network.js'\nimport { AptosContext, AptosResourcesContext } from './context.js'\nimport { EventInstance } from './models.js'\nimport { ListStateStorage } from '@sentio/runtime'\nimport {\n MoveFetchConfig,\n Data_AptResource,\n HandleInterval,\n ProcessResult,\n Data_AptEvent,\n Data_AptCall,\n} from '@sentio/protos'\nimport { ServerError, Status } from 'nice-grpc'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_AptResource) => Promise<ProcessResult>\n}\n\nexport class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {\n static INSTANCE = new AptosProcessorState()\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler<Data_AptEvent>[] = []\n callHandlers: CallHandler<Data_AptCall>[] = []\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n AptosProcessorState.INSTANCE.addValue(this)\n this.loadTypes(MOVE_CODER)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void,\n includedFailed = false,\n fetchConfig?: MoveFetchConfig\n ): this {\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\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 call = data.transaction as Transaction_UserTransaction\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(data.transaction.version),\n call\n )\n await handler(call, ctx)\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onMoveEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: MoveFetchConfig\n ): this {\n let _filters: EventFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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\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 Transaction_UserTransaction\n if (!txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn\n )\n\n const events = txn.events\n txn.events = []\n for (const evt of events) {\n const eventInstance = evt as EventInstance\n const decoded = MOVE_CODER.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: MoveFetchConfig\n ): this {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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\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 Transaction_UserTransaction\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = MOVE_CODER.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n loadTypes(registry: MoveCoder) {\n if (registry.contains(this.config.address, this.moduleName)) {\n return\n }\n this.loadTypesInternal(registry)\n }\n\n protected loadTypesInternal(registry: MoveCoder) {\n // should be override by subclass\n console.log('')\n }\n}\n\nexport class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {\n static INSTANCE = new AptosAccountProcessorState()\n}\n\nexport class AptosResourcesProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosResourcesProcessor {\n return new AptosResourcesProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n AptosAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (data) {\n if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n const timestamp = Number(data.timestampMicros)\n\n const ctx = new AptosResourcesContext(\n processor.config.network,\n processor.config.address,\n data.version,\n timestamp\n )\n await handler(data.resources as MoveResource[], ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type: type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,\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 onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,\n versionInterval = 100000,\n backfillVersionInterval = 400000,\n typePrefix?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },\n typePrefix\n )\n }\n}\n\nfunction configure(options: AptosBindOptions): IndexConfigure {\n let startVersion = 0n\n if (options.startVersion !== undefined) {\n if (typeof options.startVersion === 'number') {\n startVersion = BigInt(options.startVersion)\n } else {\n startVersion = options.startVersion\n }\n }\n\n return {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n}\n"]}
|
package/lib/aptos/context.d.ts
CHANGED
@@ -12,7 +12,7 @@ export declare class AptosContext extends BaseContext {
|
|
12
12
|
getChainId(): string;
|
13
13
|
getMetaData(name: string, labels: Labels): RecordMetaData;
|
14
14
|
}
|
15
|
-
export declare class
|
15
|
+
export declare class AptosResourcesContext extends BaseContext {
|
16
16
|
address: string;
|
17
17
|
network: AptosNetwork;
|
18
18
|
version: bigint;
|
package/lib/aptos/context.js
CHANGED
package/lib/aptos/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/aptos/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEvE,OAAO,EAAgB,UAAU,EAAE,MAAM,cAAc,CAAA;AAEvD,MAAM,OAAO,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,UAAU,CAAQ;IAClB,OAAO,CAAQ;IACf,WAAW,CAA6B;IAExC,YACE,UAAkB,EAClB,OAAqB,EACrB,OAAe,EACf,OAAe,EACf,WAAyC;QAEzC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,UAAU;QACR,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,WAAW,EAAE,IAAI,C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,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;YAC7C,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IACpD,OAAO,CAAQ;IACf,OAAO,CAAc;IACrB,OAAO,CAAQ;IACf,iBAAiB,CAAQ;IAEzB,YAAY,OAAqB,EAAE,OAAe,EAAE,OAAe,EAAE,iBAAyB;QAC5F,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED,UAAU;QACR,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, BaseContext, normalizeLabels } from '@sentio/sdk'\nimport { Transaction_UserTransaction } from './move-types.js'\nimport { AptosNetwork, getChainId } from './network.js'\n\nexport class AptosContext extends BaseContext {\n address: string\n network: AptosNetwork\n moduleName: string\n version: bigint\n transaction: Transaction_UserTransaction\n\n constructor(\n moduleName: string,\n network: AptosNetwork,\n address: string,\n version: bigint,\n transaction?: Transaction_UserTransaction\n ) {\n super()\n this.address = address.toLowerCase()\n this.network = network\n this.moduleName = moduleName\n this.version = version\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: this.transaction?.hash || '', // TODO\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class AptosResourcesContext extends BaseContext {\n address: string\n network: AptosNetwork\n version: bigint\n timestampInMicros: number\n\n constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {\n super()\n this.address = address\n this.network = network\n this.version = version\n this.timestampInMicros = timestampInMicros\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: 'resources',\n blockNumber: this.version,\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Gauge } from '@sentio/sdk';
|
2
2
|
import { BigDecimal } from '@sentio/bigdecimal';
|
3
|
-
import {
|
3
|
+
import { AptosResourcesContext, TypedMoveResource, MoveResource, AptosContext } from '@sentio/sdk/aptos';
|
4
4
|
export interface PoolAdaptor<T> {
|
5
5
|
getXReserve(pool: T): bigint;
|
6
6
|
getYReserve(pool: T): bigint;
|
@@ -16,7 +16,7 @@ export declare class AptosDex<T> {
|
|
16
16
|
tvlByCoin: Gauge;
|
17
17
|
constructor(volume: Gauge, volumeByCoin: Gauge, tvlAll: Gauge, tvlByCoin: Gauge, tvlByPool: Gauge, poolAdaptor: PoolAdaptor<T>);
|
18
18
|
recordTradingVolume(ctx: AptosContext, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint, extraLabels?: any): Promise<BigDecimal>;
|
19
|
-
syncPools(resources: MoveResource[], ctx:
|
19
|
+
syncPools(resources: MoveResource[], ctx: AptosResourcesContext, poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void): Promise<void>;
|
20
20
|
}
|
21
21
|
export declare function getPair(coinx: string, coiny: string): Promise<string>;
|
22
22
|
export declare function getPairValue(ctx: AptosContext, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint): Promise<BigDecimal>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-dex.js","sourceRoot":"","sources":["../../../src/aptos/ext/aptos-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAIL,gBAAgB,GAEjB,MAAM,mBAAmB,CAAA;AAS1B,MAAM,OAAO,QAAQ;IACnB,WAAW,CAAgB;IAC3B,MAAM,CAAO;IACb,YAAY,CAAO;IACnB,MAAM,CAAO;IACb,SAAS,CAAO;IAChB,SAAS,CAAO;IAEhB,YACE,MAAa,EACb,YAAmB,EACnB,MAAa,EACb,SAAgB,EAChB,SAAgB,EAChB,WAA2B;QAE3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,GAAiB,EACjB,KAAa,EACb,KAAa,EACb,WAAmB,EACnB,WAAmB,EACnB,WAAiB;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,CAAC,KAAK,CAAC,CAAA;IACrC,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;IACrC,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAA;IAC3C,IAAI,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;IAE5B,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;QAC9B,OAAO,MAAM,CAAA;KACd;IAED,IAAI,UAAU,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAC1E,MAAM,GAAG,KAAK,CAAA;QAEd,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IACD,IAAI,UAAU,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAE1E,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { Gauge } from '@sentio/sdk'\nimport { BigDecimal } from '@sentio/bigdecimal'\nimport { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'\nimport {\n AptosResourceContext,\n TypedMoveResource,\n MoveResource,\n defaultMoveCoder,\n AptosContext,\n} from '@sentio/sdk/aptos'\n\nexport interface PoolAdaptor<T> {\n getXReserve(pool: T): bigint\n getYReserve(pool: T): bigint\n getExtraPoolTags(pool: TypedMoveResource<T>): any\n poolTypeName: string\n}\n\nexport class AptosDex<T> {\n poolAdaptor: PoolAdaptor<T>\n volume: Gauge\n volumeByCoin: Gauge\n tvlAll: Gauge\n tvlByPool: Gauge\n tvlByCoin: Gauge\n\n constructor(\n volume: Gauge,\n volumeByCoin: Gauge,\n tvlAll: Gauge,\n tvlByCoin: Gauge,\n tvlByPool: Gauge,\n poolAdaptor: PoolAdaptor<T>\n ) {\n this.volume = volume\n this.volumeByCoin = volumeByCoin\n this.tvlAll = tvlAll\n this.tvlByPool = tvlByPool\n this.tvlByCoin = tvlByCoin\n this.poolAdaptor = poolAdaptor\n }\n\n async recordTradingVolume(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint,\n extraLabels?: any\n ): Promise<BigDecimal> {\n let result = BigDecimal(0)\n\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n return result\n }\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n const timestamp = ctx.transaction.timestamp\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n const pair = await getPair(coinx, coiny)\n const baseLabels: Record<string, string> = extraLabels ? { ...extraLabels, pair } : { pair }\n if (whitelistx) {\n resultX = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n }\n if (whitelisty) {\n resultY = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n }\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n const total = resultX.plus(resultY)\n if (total.gt(0)) {\n this.volume.record(ctx, total, {\n ...baseLabels,\n bridge: coinXInfo.bridge,\n })\n }\n if (resultX.gt(0)) {\n this.volumeByCoin.record(ctx, resultX, {\n coin: coinXInfo.symbol,\n bridge: coinXInfo.bridge,\n type: coinXInfo.token_type.type,\n })\n }\n if (resultY.gt(0)) {\n this.volumeByCoin.record(ctx, resultY, {\n coin: coinYInfo.symbol,\n bridge: coinYInfo.bridge,\n type: coinYInfo.token_type.type,\n })\n }\n result = resultX.plus(resultY).div(2)\n return result\n }\n\n async syncPools(\n resources: MoveResource[],\n ctx: AptosResourceContext,\n poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void\n ) {\n const pools: TypedMoveResource<T>[] = defaultMoveCoder().filterAndDecodeResources(\n this.poolAdaptor.poolTypeName,\n resources\n )\n\n const volumeByCoin = new Map<string, BigDecimal>()\n const timestamp = ctx.timestampInMicros\n\n console.log('num of pools: ', pools.length, ctx.version.toString())\n\n let tvlAllValue = BigDecimal(0)\n for (const pool of pools) {\n // savePool(ctx.version, pool.type_arguments)\n const coinx = pool.type_arguments[0]\n const coiny = pool.type_arguments[1]\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n continue\n }\n\n const pair = await getPair(coinx, coiny)\n const extraLabels = this.poolAdaptor.getExtraPoolTags(pool)\n const baseLabels: Record<string, string> = { ...extraLabels, pair }\n\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n\n const coinx_amount = this.poolAdaptor.getXReserve(pool.data_decoded)\n const coiny_amount = this.poolAdaptor.getYReserve(pool.data_decoded)\n\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n\n if (whitelistx) {\n resultX = await calculateValueInUsd(coinx_amount, coinXInfo, timestamp)\n let coinXTotal = volumeByCoin.get(coinXInfo.token_type.type)\n if (!coinXTotal) {\n coinXTotal = resultX\n } else {\n coinXTotal = coinXTotal.plus(resultX)\n }\n volumeByCoin.set(coinXInfo.token_type.type, coinXTotal)\n }\n if (whitelisty) {\n resultY = await calculateValueInUsd(coiny_amount, coinYInfo, timestamp)\n let coinYTotal = volumeByCoin.get(coinYInfo.token_type.type)\n if (!coinYTotal) {\n coinYTotal = resultY\n } else {\n coinYTotal = coinYTotal.plus(resultY)\n }\n volumeByCoin.set(coinYInfo.token_type.type, coinYTotal)\n }\n\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n\n const poolValue = resultX.plus(resultY)\n\n if (poolValue.isGreaterThan(0)) {\n this.tvlByPool.record(ctx, poolValue, baseLabels)\n }\n tvlAllValue = tvlAllValue.plus(poolValue)\n }\n this.tvlAll.record(ctx, tvlAllValue)\n\n if (poolsHandler) {\n poolsHandler(pools)\n }\n\n for (const [k, v] of volumeByCoin) {\n const coinInfo = whitelistCoins().get(k)\n if (!coinInfo) {\n throw Error('unexpected coin ' + k)\n }\n // const price = await getPrice(coinInfo, timestamp)\n // priceGauge.record(ctx, price, { coin: coinInfo.symbol })\n if (v.isGreaterThan(0)) {\n this.tvlByCoin.record(ctx, v, {\n coin: coinInfo.symbol,\n bridge: coinInfo.bridge,\n type: coinInfo.token_type.type,\n })\n }\n }\n }\n}\n\nexport async function getPair(coinx: string, coiny: string): Promise<string> {\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n if (coinXInfo.symbol.localeCompare(coinYInfo.symbol) > 0) {\n return `${coinYInfo.symbol}-${coinXInfo.symbol}`\n }\n return `${coinXInfo.symbol}-${coinYInfo.symbol}`\n}\n\nexport async function getPairValue(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint\n): Promise<BigDecimal> {\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n const timestamp = ctx.transaction.timestamp\n let result = BigDecimal(0.0)\n\n if (!whitelistx || !whitelisty) {\n return result\n }\n\n if (whitelistx) {\n const value = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n result = value\n\n if (!whitelisty) {\n result = result.plus(value)\n }\n }\n if (whitelisty) {\n const value = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n\n if (!whitelistx) {\n result = result.plus(value)\n }\n }\n\n return result\n}\n"]}
|
1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9B,OAAO,MAAM,CAAA;KACd;IAED,IAAI,UAAU,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAC1E,MAAM,GAAG,KAAK,CAAA;QAEd,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IACD,IAAI,UAAU,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAE1E,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { Gauge } from '@sentio/sdk'\nimport { BigDecimal } from '@sentio/bigdecimal'\nimport { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'\nimport {\n AptosResourcesContext,\n TypedMoveResource,\n MoveResource,\n defaultMoveCoder,\n AptosContext,\n} from '@sentio/sdk/aptos'\n\nexport interface PoolAdaptor<T> {\n getXReserve(pool: T): bigint\n getYReserve(pool: T): bigint\n getExtraPoolTags(pool: TypedMoveResource<T>): any\n poolTypeName: string\n}\n\nexport class AptosDex<T> {\n poolAdaptor: PoolAdaptor<T>\n volume: Gauge\n volumeByCoin: Gauge\n tvlAll: Gauge\n tvlByPool: Gauge\n tvlByCoin: Gauge\n\n constructor(\n volume: Gauge,\n volumeByCoin: Gauge,\n tvlAll: Gauge,\n tvlByCoin: Gauge,\n tvlByPool: Gauge,\n poolAdaptor: PoolAdaptor<T>\n ) {\n this.volume = volume\n this.volumeByCoin = volumeByCoin\n this.tvlAll = tvlAll\n this.tvlByPool = tvlByPool\n this.tvlByCoin = tvlByCoin\n this.poolAdaptor = poolAdaptor\n }\n\n async recordTradingVolume(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint,\n extraLabels?: any\n ): Promise<BigDecimal> {\n let result = BigDecimal(0)\n\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n return result\n }\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n const timestamp = ctx.transaction.timestamp\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n const pair = await getPair(coinx, coiny)\n const baseLabels: Record<string, string> = extraLabels ? { ...extraLabels, pair } : { pair }\n if (whitelistx) {\n resultX = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n }\n if (whitelisty) {\n resultY = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n }\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n const total = resultX.plus(resultY)\n if (total.gt(0)) {\n this.volume.record(ctx, total, {\n ...baseLabels,\n bridge: coinXInfo.bridge,\n })\n }\n if (resultX.gt(0)) {\n this.volumeByCoin.record(ctx, resultX, {\n coin: coinXInfo.symbol,\n bridge: coinXInfo.bridge,\n type: coinXInfo.token_type.type,\n })\n }\n if (resultY.gt(0)) {\n this.volumeByCoin.record(ctx, resultY, {\n coin: coinYInfo.symbol,\n bridge: coinYInfo.bridge,\n type: coinYInfo.token_type.type,\n })\n }\n result = resultX.plus(resultY).div(2)\n return result\n }\n\n async syncPools(\n resources: MoveResource[],\n ctx: AptosResourcesContext,\n poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void\n ) {\n const pools: TypedMoveResource<T>[] = defaultMoveCoder().filterAndDecodeResources(\n this.poolAdaptor.poolTypeName,\n resources\n )\n\n const volumeByCoin = new Map<string, BigDecimal>()\n const timestamp = ctx.timestampInMicros\n\n console.log('num of pools: ', pools.length, ctx.version.toString())\n\n let tvlAllValue = BigDecimal(0)\n for (const pool of pools) {\n // savePool(ctx.version, pool.type_arguments)\n const coinx = pool.type_arguments[0]\n const coiny = pool.type_arguments[1]\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n continue\n }\n\n const pair = await getPair(coinx, coiny)\n const extraLabels = this.poolAdaptor.getExtraPoolTags(pool)\n const baseLabels: Record<string, string> = { ...extraLabels, pair }\n\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n\n const coinx_amount = this.poolAdaptor.getXReserve(pool.data_decoded)\n const coiny_amount = this.poolAdaptor.getYReserve(pool.data_decoded)\n\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n\n if (whitelistx) {\n resultX = await calculateValueInUsd(coinx_amount, coinXInfo, timestamp)\n let coinXTotal = volumeByCoin.get(coinXInfo.token_type.type)\n if (!coinXTotal) {\n coinXTotal = resultX\n } else {\n coinXTotal = coinXTotal.plus(resultX)\n }\n volumeByCoin.set(coinXInfo.token_type.type, coinXTotal)\n }\n if (whitelisty) {\n resultY = await calculateValueInUsd(coiny_amount, coinYInfo, timestamp)\n let coinYTotal = volumeByCoin.get(coinYInfo.token_type.type)\n if (!coinYTotal) {\n coinYTotal = resultY\n } else {\n coinYTotal = coinYTotal.plus(resultY)\n }\n volumeByCoin.set(coinYInfo.token_type.type, coinYTotal)\n }\n\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n\n const poolValue = resultX.plus(resultY)\n\n if (poolValue.isGreaterThan(0)) {\n this.tvlByPool.record(ctx, poolValue, baseLabels)\n }\n tvlAllValue = tvlAllValue.plus(poolValue)\n }\n this.tvlAll.record(ctx, tvlAllValue)\n\n if (poolsHandler) {\n poolsHandler(pools)\n }\n\n for (const [k, v] of volumeByCoin) {\n const coinInfo = whitelistCoins().get(k)\n if (!coinInfo) {\n throw Error('unexpected coin ' + k)\n }\n // const price = await getPrice(coinInfo, timestamp)\n // priceGauge.record(ctx, price, { coin: coinInfo.symbol })\n if (v.isGreaterThan(0)) {\n this.tvlByCoin.record(ctx, v, {\n coin: coinInfo.symbol,\n bridge: coinInfo.bridge,\n type: coinInfo.token_type.type,\n })\n }\n }\n }\n}\n\nexport async function getPair(coinx: string, coiny: string): Promise<string> {\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n if (coinXInfo.symbol.localeCompare(coinYInfo.symbol) > 0) {\n return `${coinYInfo.symbol}-${coinXInfo.symbol}`\n }\n return `${coinXInfo.symbol}-${coinYInfo.symbol}`\n}\n\nexport async function getPairValue(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint\n): Promise<BigDecimal> {\n const whitelistx = whiteListed(coinx)\n const whitelisty = whiteListed(coiny)\n const coinXInfo = await getCoinInfo(coinx)\n const coinYInfo = await getCoinInfo(coiny)\n const timestamp = ctx.transaction.timestamp\n let result = BigDecimal(0.0)\n\n if (!whitelistx || !whitelisty) {\n return result\n }\n\n if (whitelistx) {\n const value = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n result = value\n\n if (!whitelisty) {\n result = result.plus(value)\n }\n }\n if (whitelisty) {\n const value = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n\n if (!whitelistx) {\n result = result.plus(value)\n }\n }\n\n return result\n}\n"]}
|
package/lib/aptos/index.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
export * from './move-types.js';
|
2
2
|
export type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js';
|
3
3
|
export { defaultMoveCoder, MoveCoder } from './move-coder.js';
|
4
|
-
export { AptosBaseProcessor,
|
5
|
-
export { AptosContext,
|
4
|
+
export { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js';
|
5
|
+
export { AptosContext, AptosResourcesContext } from './context.js';
|
6
6
|
export { AptosBindOptions, AptosNetwork } from './network.js';
|
7
7
|
export * from './api.js';
|
8
8
|
export { ModuleClient } from './module-client.js';
|
package/lib/aptos/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export * from './move-types.js';
|
2
2
|
export { defaultMoveCoder, MoveCoder } from './move-coder.js';
|
3
|
-
export { AptosBaseProcessor,
|
4
|
-
export { AptosContext,
|
3
|
+
export { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js';
|
4
|
+
export { AptosContext, AptosResourcesContext } from './context.js';
|
5
5
|
export { AptosBindOptions, AptosNetwork } from './network.js';
|
6
6
|
export * from './api.js';
|
7
7
|
export { ModuleClient } from './module-client.js';
|
package/lib/aptos/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAClF,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA","sourcesContent":["export * from './move-types.js'\nexport type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nexport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nexport { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js'\nexport { AptosContext, AptosResourcesContext } from './context.js'\nexport { AptosBindOptions, AptosNetwork } from './network.js'\nexport * from './api.js'\nexport { ModuleClient } from './module-client.js'\n\nexport { AptosPlugin } from './aptos-plugin.js'\n"]}
|
package/lib/eth/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export { BaseProcessor } from './base-processor.js';
|
2
2
|
export { GenericProcessor } from './generic-processor.js';
|
3
3
|
export { BaseProcessorTemplate } from './base-processor-template.js';
|
4
|
+
export { AccountProcessor } from './account-processor.js';
|
4
5
|
export { getProvider, DummyProvider, getNetworkFromCtxOrNetworkish } from './provider.js';
|
5
6
|
export type { TypedCallTrace, Trace } from './trace.js';
|
6
7
|
export * from './eth.js';
|
package/lib/eth/index.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export { BaseProcessor } from './base-processor.js';
|
2
2
|
export { GenericProcessor } from './generic-processor.js';
|
3
3
|
export { BaseProcessorTemplate } from './base-processor-template.js';
|
4
|
+
export { AccountProcessor } from './account-processor.js';
|
4
5
|
export { getProvider, DummyProvider, getNetworkFromCtxOrNetworkish } from './provider.js';
|
5
6
|
export * from './eth.js';
|
6
7
|
export { BindOptions, AccountBindOptions } from './bind-options.js';
|
package/lib/eth/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAA;AAEzF,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC3F,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAE/E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA","sourcesContent":["export { BaseProcessor } from './base-processor.js'\nexport { GenericProcessor } from './generic-processor.js'\nexport { BaseProcessorTemplate } from './base-processor-template.js'\nexport { getProvider, DummyProvider, getNetworkFromCtxOrNetworkish } from './provider.js'\nexport type { TypedCallTrace, Trace } from './trace.js'\nexport * from './eth.js'\nexport { BindOptions, AccountBindOptions } from './bind-options.js'\nexport { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds.js'\nexport { ContractContext, ContractView, BoundContractView } from './context.js'\n\nexport { EthPlugin } from './eth-plugin.js'\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAA;AAEzF,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC3F,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAE/E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA","sourcesContent":["export { BaseProcessor } from './base-processor.js'\nexport { GenericProcessor } from './generic-processor.js'\nexport { BaseProcessorTemplate } from './base-processor-template.js'\nexport { AccountProcessor } from './account-processor.js'\nexport { getProvider, DummyProvider, getNetworkFromCtxOrNetworkish } from './provider.js'\nexport type { TypedCallTrace, Trace } from './trace.js'\nexport * from './eth.js'\nexport { BindOptions, AccountBindOptions } from './bind-options.js'\nexport { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds.js'\nexport { ContractContext, ContractView, BoundContractView } from './context.js'\n\nexport { EthPlugin } from './eth-plugin.js'\n"]}
|
package/lib/sui/context.d.ts
CHANGED
@@ -13,7 +13,7 @@ export declare class SuiContext extends BaseContext {
|
|
13
13
|
getChainId(): string;
|
14
14
|
getMetaData(name: string, labels: Labels): RecordMetaData;
|
15
15
|
}
|
16
|
-
export declare class
|
16
|
+
export declare class SuiObjectsContext extends BaseContext {
|
17
17
|
address: string;
|
18
18
|
network: SuiNetwork;
|
19
19
|
slot: bigint;
|
package/lib/sui/context.js
CHANGED
package/lib/sui/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/sui/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAc,UAAU,EAAE,MAAM,cAAc,CAAA;AAGrD,MAAM,OAAO,UAAW,SAAQ,WAAW;IACzC,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,UAAU,CAAQ;IAClB,SAAS,CAAM;IACf,IAAI,CAAQ;IACZ,WAAW,CAAwB;IAEnC,YACE,UAAkB,EAClB,OAAmB,EACnB,OAAe,EACf,SAAe,EACf,IAAY,EACZ,WAAoC;QAEpC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QAC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AAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,SAAS;YACvB,WAAW,EAAE,IAAI,CAAC,IAAI;YACtB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, BaseContext, normalizeLabels } from '../index.js'\nimport { SuiNetwork, getChainId } from './network.js'\nimport { SuiTransactionResponse } from '@mysten/sui.js'\n\nexport class SuiContext extends BaseContext {\n address: string\n network: SuiNetwork\n moduleName: string\n timestamp: Date\n slot: bigint\n transaction: SuiTransactionResponse\n\n constructor(\n moduleName: string,\n network: SuiNetwork,\n address: string,\n timestamp: Date,\n slot: bigint,\n transaction?: SuiTransactionResponse\n ) {\n super()\n this.address = address.toLowerCase()\n this.network = network\n this.moduleName = moduleName\n this.timestamp = timestamp\n this.slot = slot\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.slot,\n transactionIndex: 0,\n transactionHash: this.transaction?.certificate.transactionDigest || '', // TODO\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class SuiObjectsContext extends BaseContext {\n address: string\n network: SuiNetwork\n slot: bigint\n timestamp: Date\n\n constructor(network: SuiNetwork, address: string, slot: bigint, timestamp: Date) {\n super()\n this.address = address\n this.network = network\n this.slot = slot\n this.timestamp = timestamp\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: 'objects',\n blockNumber: this.slot,\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
|
package/lib/sui/sui-plugin.js
CHANGED
@@ -61,7 +61,7 @@ export class SuiPlugin extends Plugin {
|
|
61
61
|
});
|
62
62
|
for (const handler of processor.objectHandlers) {
|
63
63
|
const handlerId = this.suiObjectHandlers.push(handler.handler) - 1;
|
64
|
-
accountConfig.
|
64
|
+
accountConfig.moveIntervalConfigs.push({
|
65
65
|
intervalConfig: {
|
66
66
|
handlerId: handlerId,
|
67
67
|
minutes: 0,
|
@@ -69,6 +69,8 @@ export class SuiPlugin extends Plugin {
|
|
69
69
|
slot: 0,
|
70
70
|
slotInterval: handler.versionInterval,
|
71
71
|
},
|
72
|
+
type: handler.type || '',
|
73
|
+
ownerType: processor.ownerType,
|
72
74
|
});
|
73
75
|
}
|
74
76
|
config.accountConfigs.push(accountConfig);
|
@@ -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,GAKZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAElB,gBAAgB,GAAyD,EAAE,CAAA;IAC3E,eAAe,GAAuD,EAAE,CAAA;IACxE,iBAAiB,GAA2D,EAAE,CAAA;IAEtF,KAAK,CAAC,SAAS,CAAC,M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C3B,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","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} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { getChainId } from './network.js'\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n\n private suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[] = []\n private suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[] = []\n private suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[] = []\n\n async configure(config: ProcessConfigResponse) {\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: getChainId(suiProcessor.config.network),\n address: suiProcessor.config.address,\n abi: '',\n },\n startBlock: BigInt(suiProcessor.config.startTimestamp),\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = this.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 = this.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: processor.config.address,\n chainId: processor.getChainId(),\n startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = this.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.suiIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL]\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.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.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.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,EA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OAAO,CAAC,UAAU,EAAE;YAC1C,QAAQ,CAAC,IAAI,CACX,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACpD,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","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} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { getChainId } from './network.js'\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n\n private suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[] = []\n private suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[] = []\n private suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[] = []\n\n async configure(config: ProcessConfigResponse) {\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: getChainId(suiProcessor.config.network),\n address: suiProcessor.config.address,\n abi: '',\n },\n startBlock: BigInt(suiProcessor.config.startTimestamp),\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = this.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 = this.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: processor.config.address,\n chainId: processor.getChainId(),\n startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = this.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 },\n type: handler.type || '',\n ownerType: processor.ownerType,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL]\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.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.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.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,7 +1,7 @@
|
|
1
|
-
import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig, Data_SuiObject, ProcessResult, HandleInterval } from '@sentio/protos';
|
1
|
+
import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig, Data_SuiObject, ProcessResult, HandleInterval, MoveOnIntervalConfig_OwnerType } from '@sentio/protos';
|
2
2
|
import { ListStateStorage } from '@sentio/runtime';
|
3
3
|
import { SuiNetwork } from './network.js';
|
4
|
-
import { SuiContext,
|
4
|
+
import { SuiContext, SuiObjectsContext } from './context.js';
|
5
5
|
import { MoveEvent, MoveCall, SuiMoveObject } from '@mysten/sui.js';
|
6
6
|
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js';
|
7
7
|
declare class IndexConfigure {
|
@@ -28,21 +28,26 @@ export declare class SuiBaseProcessor {
|
|
28
28
|
onEntryFunctionCall(handler: (call: MoveCall, ctx: SuiContext) => void, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[], fetchConfig?: MoveFetchConfig): SuiBaseProcessor;
|
29
29
|
}
|
30
30
|
declare class ObjectHandler {
|
31
|
+
type?: string;
|
31
32
|
versionInterval?: HandleInterval;
|
32
33
|
timeIntervalInMinutes?: HandleInterval;
|
33
34
|
handler: (resource: Data_SuiObject) => Promise<ProcessResult>;
|
34
35
|
}
|
35
|
-
export declare class SuiAccountProcessorState extends ListStateStorage<
|
36
|
+
export declare class SuiAccountProcessorState extends ListStateStorage<SuiObjectsProcessor> {
|
36
37
|
static INSTANCE: SuiAccountProcessorState;
|
37
38
|
}
|
38
|
-
|
39
|
+
declare class SuiObjectsBindOptions extends SuiBindOptions {
|
40
|
+
ownerType: MoveOnIntervalConfig_OwnerType;
|
41
|
+
}
|
42
|
+
export declare class SuiObjectsProcessor {
|
39
43
|
config: IndexConfigure;
|
44
|
+
ownerType: MoveOnIntervalConfig_OwnerType;
|
40
45
|
objectHandlers: ObjectHandler[];
|
41
|
-
static bind(options:
|
42
|
-
protected constructor(options:
|
46
|
+
static bind(options: SuiObjectsBindOptions): SuiObjectsProcessor;
|
47
|
+
protected constructor(options: SuiObjectsBindOptions);
|
43
48
|
getChainId(): string;
|
44
49
|
private onInterval;
|
45
|
-
onTimeInterval(handler: (objects: SuiMoveObject[], ctx:
|
46
|
-
onSlotInterval(handler: (objects: SuiMoveObject[], ctx:
|
50
|
+
onTimeInterval(handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => void, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string): this;
|
51
|
+
onSlotInterval(handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => void, slotInterval?: number, backfillSlotInterval?: number, type?: string): this;
|
47
52
|
}
|
48
53
|
export {};
|
package/lib/sui/sui-processor.js
CHANGED
@@ -2,7 +2,7 @@ import { MoveFetchConfig, } from '@sentio/protos';
|
|
2
2
|
import { ListStateStorage } from '@sentio/runtime';
|
3
3
|
import { SuiNetwork, getChainId } from './network.js';
|
4
4
|
import { ServerError, Status } from 'nice-grpc';
|
5
|
-
import { SuiContext,
|
5
|
+
import { SuiContext, SuiObjectsContext } from './context.js';
|
6
6
|
import { getMoveCalls } from './utils.js';
|
7
7
|
import { defaultMoveCoder } from './move-coder.js';
|
8
8
|
class IndexConfigure {
|
@@ -106,6 +106,7 @@ export class SuiBaseProcessor {
|
|
106
106
|
}
|
107
107
|
}
|
108
108
|
class ObjectHandler {
|
109
|
+
type;
|
109
110
|
versionInterval;
|
110
111
|
timeIntervalInMinutes;
|
111
112
|
handler;
|
@@ -113,40 +114,46 @@ class ObjectHandler {
|
|
113
114
|
export class SuiAccountProcessorState extends ListStateStorage {
|
114
115
|
static INSTANCE = new SuiAccountProcessorState();
|
115
116
|
}
|
116
|
-
|
117
|
+
class SuiObjectsBindOptions extends SuiBindOptions {
|
118
|
+
ownerType;
|
119
|
+
}
|
120
|
+
export class SuiObjectsProcessor {
|
117
121
|
config;
|
122
|
+
ownerType;
|
118
123
|
objectHandlers = [];
|
119
124
|
static bind(options) {
|
120
|
-
return new
|
125
|
+
return new SuiObjectsProcessor(options);
|
121
126
|
}
|
122
127
|
constructor(options) {
|
123
128
|
this.config = configure(options);
|
129
|
+
this.ownerType = options.ownerType;
|
124
130
|
SuiAccountProcessorState.INSTANCE.addValue(this);
|
125
131
|
}
|
126
132
|
getChainId() {
|
127
133
|
return getChainId(this.config.network);
|
128
134
|
}
|
129
|
-
onInterval(handler, timeInterval, versionInterval) {
|
135
|
+
onInterval(handler, timeInterval, versionInterval, type) {
|
130
136
|
const processor = this;
|
131
137
|
this.objectHandlers.push({
|
132
138
|
handler: async function (data) {
|
133
|
-
const ctx = new
|
139
|
+
const ctx = new SuiObjectsContext(processor.config.network, processor.config.address, data.slot, data.timestamp || new Date(0));
|
134
140
|
await handler(data.objects, ctx);
|
135
141
|
return ctx.getProcessResult();
|
136
142
|
},
|
137
143
|
timeIntervalInMinutes: timeInterval,
|
138
144
|
versionInterval: versionInterval,
|
145
|
+
type,
|
139
146
|
});
|
140
147
|
return this;
|
141
148
|
}
|
142
|
-
onTimeInterval(handler, timeIntervalInMinutes = 60, backfillTimeIntervalInMinutes = 240) {
|
149
|
+
onTimeInterval(handler, timeIntervalInMinutes = 60, backfillTimeIntervalInMinutes = 240, type) {
|
143
150
|
return this.onInterval(handler, {
|
144
151
|
recentInterval: timeIntervalInMinutes,
|
145
152
|
backfillInterval: backfillTimeIntervalInMinutes,
|
146
|
-
}, undefined);
|
153
|
+
}, undefined, type);
|
147
154
|
}
|
148
|
-
onSlotInterval(handler, slotInterval = 100000, backfillSlotInterval = 400000) {
|
149
|
-
return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval });
|
155
|
+
onSlotInterval(handler, slotInterval = 100000, backfillSlotInterval = 400000, type) {
|
156
|
+
return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval }, type);
|
150
157
|
}
|
151
158
|
}
|
152
159
|
function configure(options) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/sui/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,GAIhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAG3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,cAAc;IAClB,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,cAAc,CAAQ;CACvB;AAED,MAAM,OAAO,cAAc;IACzB,OAAO,CAAQ;IACf,OAAO,CAAa;IACpB,cAAc,CAAS;CACxB;AAED,MAAM,OAAO,iBAAkB,SAAQ,gBAAkC;IACvE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;AAG3C,MAAM,OAAO,gBAAgB;IAClB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IAEtB,aAAa,GAAkC,EAAE,CAAA;IACjD,YAAY,GAAgC,EAAE,CAAA;IAE9C,YAAY,IAAY,EAAE,OAAuB;QAC/C,IAAI,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,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC,CAAA;IACtH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAuB;IACxC,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC;QAC3C,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC,QAAQ;KAChD,CAAA;AACH,CAAC","sourcesContent":["import {\n Data_SuiCall,\n Data_SuiEvent,\n MoveFetchConfig,\n Data_SuiObject,\n ProcessResult,\n HandleInterval,\n} from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { SuiNetwork, getChainId } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext, SuiObjectContext } from './context.js'\nimport { MoveEvent, SuiTransactionResponse, MoveCall, SuiMoveObject } from '@mysten/sui.js'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder } from './move-coder.js'\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startTimestamp: number\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startTimestamp?: number\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\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n public onMoveEvent(\n handler: (event: MoveEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: MoveFetchConfig\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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\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 SuiTransactionResponse\n if (!txn.effects.events || !txn.effects.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\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 )\n\n const events = txn.effects.events\n txn.effects.events = []\n for (const evt of events) {\n if ('moveEvent' in evt) {\n const eventInstance = evt.moveEvent as MoveEvent\n const decoded = defaultMoveCoder().decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n }\n\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCall, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: MoveFetchConfig\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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\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 SuiTransactionResponse\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 )\n if (tx) {\n const calls: MoveCall[] = getMoveCalls(tx)\n if (calls.length !== 1) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)\n }\n const payload = calls[0]\n const decoded = defaultMoveCoder().decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n\nclass ObjectHandler {\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiAccountProcessor> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nexport class SuiAccountProcessor {\n config: IndexConfigure\n\n objectHandlers: ObjectHandler[] = []\n\n static bind(options: SuiBindOptions): SuiAccountProcessor {\n return new SuiAccountProcessor(options)\n }\n\n protected constructor(options: SuiBindOptions) {\n this.config = configure(options)\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: SuiMoveObject[], ctx: SuiObjectContext) => void,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined\n ): this {\n const processor = this\n this.objectHandlers.push({\n handler: async function (data) {\n const ctx = new SuiObjectContext(\n processor.config.network,\n processor.config.address,\n data.slot,\n data.timestamp || new Date(0)\n )\n await handler(data.objects as SuiMoveObject[], ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => void,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined\n )\n }\n\n public onSlotInterval(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => void,\n slotInterval = 100000,\n backfillSlotInterval = 400000\n ): this {\n return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval })\n }\n}\n\nfunction configure(options: SuiBindOptions): IndexConfigure {\n return {\n startTimestamp: options.startTimestamp || 0,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/sui/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,GAKhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAG5D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,cAAc;IAClB,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,cAAc,CAAQ;CACvB;AAED,MAAM,OAAO,cAAc;IACzB,OAAO,CAAQ;IACf,OAAO,CAAa;IACpB,cAAc,CAAS;CACxB;AAED,MAAM,OAAO,iBAAkB,SAAQ,gBAAkC;IACvE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;AAG3C,MAAM,OAAO,gBAAgB;IAClB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IAEtB,aAAa,GAAkC,EAAE,CAAA;IACjD,YAAY,GAAgC,EAAE,CAAA;IAE9C,YAAY,IAAY,EAAE,OAAuB;QAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;QAChC,iBAAiB,CAAC,QAAQ,CAAC,QAAQ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,MAAM,EACrB,oBAAoB,GAAG,MAAM,EAC7B,IAAa;QAEb,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,SAAS,EACT,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,EACxE,IAAI,CACL,CAAA;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAuB;IACxC,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC;QAC3C,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC,QAAQ;KAChD,CAAA;AACH,CAAC","sourcesContent":["import {\n Data_SuiCall,\n Data_SuiEvent,\n MoveFetchConfig,\n Data_SuiObject,\n ProcessResult,\n HandleInterval,\n MoveOnIntervalConfig_OwnerType,\n} from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { SuiNetwork, getChainId } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext, SuiObjectsContext } from './context.js'\nimport { MoveEvent, SuiTransactionResponse, MoveCall, SuiMoveObject } from '@mysten/sui.js'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder } from './move-coder.js'\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startTimestamp: number\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startTimestamp?: number\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\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n public onMoveEvent(\n handler: (event: MoveEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: MoveFetchConfig\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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\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 SuiTransactionResponse\n if (!txn.effects.events || !txn.effects.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\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 )\n\n const events = txn.effects.events\n txn.effects.events = []\n for (const evt of events) {\n if ('moveEvent' in evt) {\n const eventInstance = evt.moveEvent as MoveEvent\n const decoded = defaultMoveCoder().decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n }\n\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCall, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: MoveFetchConfig\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\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\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 SuiTransactionResponse\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 )\n if (tx) {\n const calls: MoveCall[] = getMoveCalls(tx)\n if (calls.length !== 1) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)\n }\n const payload = calls[0]\n const decoded = defaultMoveCoder().decodeFunctionPayload(payload)\n await handler(decoded, ctx)\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<SuiObjectsProcessor> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nclass SuiObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOnIntervalConfig_OwnerType\n}\n\nexport class SuiObjectsProcessor {\n config: IndexConfigure\n ownerType: MoveOnIntervalConfig_OwnerType\n\n objectHandlers: ObjectHandler[] = []\n\n static bind(options: SuiObjectsBindOptions): SuiObjectsProcessor {\n return new SuiObjectsProcessor(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 getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: SuiMoveObject[], ctx: SuiObjectsContext) => void,\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 )\n await handler(data.objects as SuiMoveObject[], 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: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => void,\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: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => void,\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 startTimestamp: options.startTimestamp || 0,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n }\n}\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
3
|
"license": "Apache-2.0",
|
4
|
-
"version": "2.9.0-rc.
|
4
|
+
"version": "2.9.0-rc.5",
|
5
5
|
"type": "module",
|
6
6
|
"scripts": {
|
7
7
|
"compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
|
@@ -23,8 +23,8 @@
|
|
23
23
|
"@project-serum/anchor": "^0.26.0",
|
24
24
|
"@sentio/bigdecimal": "^9.1.1-patch.3",
|
25
25
|
"@sentio/ethers-v6": "^1.0.25",
|
26
|
-
"@sentio/protos": "^2.9.0-rc.
|
27
|
-
"@sentio/runtime": "^2.9.0-rc.
|
26
|
+
"@sentio/protos": "^2.9.0-rc.5",
|
27
|
+
"@sentio/runtime": "^2.9.0-rc.5",
|
28
28
|
"@solana/web3.js": "^1.73.2",
|
29
29
|
"@types/prettier": "^2.7.2",
|
30
30
|
"aptos-sdk": "npm:aptos@^1.7.1",
|
@@ -80,5 +80,5 @@
|
|
80
80
|
"engines": {
|
81
81
|
"node": ">=16"
|
82
82
|
},
|
83
|
-
"gitHead": "
|
83
|
+
"gitHead": "840fa36f62ccbf52f39784893906771dc38734fe"
|
84
84
|
}
|
@@ -1,17 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
|
2
2
|
import {
|
3
3
|
AccountConfig,
|
4
|
-
MoveCallHandlerConfig,
|
5
|
-
MoveEventHandlerConfig,
|
6
4
|
ContractConfig,
|
7
5
|
Data_AptCall,
|
8
6
|
Data_AptEvent,
|
9
7
|
Data_AptResource,
|
10
8
|
DataBinding,
|
11
9
|
HandlerType,
|
10
|
+
MoveCallHandlerConfig,
|
11
|
+
MoveEventHandlerConfig,
|
12
12
|
ProcessConfigResponse,
|
13
13
|
ProcessResult,
|
14
14
|
StartRequest,
|
15
|
+
MoveOnIntervalConfig_OwnerType,
|
15
16
|
} from '@sentio/protos'
|
16
17
|
|
17
18
|
import { ServerError, Status } from 'nice-grpc'
|
@@ -87,6 +88,7 @@ export class AptosPlugin extends Plugin {
|
|
87
88
|
})
|
88
89
|
for (const handler of aptosProcessor.resourcesHandlers) {
|
89
90
|
const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1
|
91
|
+
// TODO move to only use moveIntervalConfigs
|
90
92
|
accountConfig.aptosIntervalConfigs.push({
|
91
93
|
intervalConfig: {
|
92
94
|
handlerId: handlerId,
|
@@ -97,6 +99,18 @@ export class AptosPlugin extends Plugin {
|
|
97
99
|
},
|
98
100
|
type: handler.type || '',
|
99
101
|
})
|
102
|
+
|
103
|
+
accountConfig.moveIntervalConfigs.push({
|
104
|
+
intervalConfig: {
|
105
|
+
handlerId: handlerId,
|
106
|
+
minutes: 0,
|
107
|
+
minutesInterval: handler.timeIntervalInMinutes,
|
108
|
+
slot: 0,
|
109
|
+
slotInterval: handler.versionInterval,
|
110
|
+
},
|
111
|
+
type: handler.type || '',
|
112
|
+
ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,
|
113
|
+
})
|
100
114
|
}
|
101
115
|
config.accountConfigs.push(accountConfig)
|
102
116
|
}
|
@@ -2,7 +2,7 @@ import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunc
|
|
2
2
|
|
3
3
|
import { MOVE_CODER, MoveCoder } from './move-coder.js'
|
4
4
|
import { AptosBindOptions, AptosNetwork, getChainId } from './network.js'
|
5
|
-
import { AptosContext,
|
5
|
+
import { AptosContext, AptosResourcesContext } from './context.js'
|
6
6
|
import { EventInstance } from './models.js'
|
7
7
|
import { ListStateStorage } from '@sentio/runtime'
|
8
8
|
import {
|
@@ -198,17 +198,17 @@ export class AptosBaseProcessor {
|
|
198
198
|
}
|
199
199
|
}
|
200
200
|
|
201
|
-
export class AptosAccountProcessorState extends ListStateStorage<
|
201
|
+
export class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {
|
202
202
|
static INSTANCE = new AptosAccountProcessorState()
|
203
203
|
}
|
204
204
|
|
205
|
-
export class
|
205
|
+
export class AptosResourcesProcessor {
|
206
206
|
config: IndexConfigure
|
207
207
|
|
208
208
|
resourcesHandlers: ResourceHandlder[] = []
|
209
209
|
|
210
|
-
static bind(options: AptosBindOptions):
|
211
|
-
return new
|
210
|
+
static bind(options: AptosBindOptions): AptosResourcesProcessor {
|
211
|
+
return new AptosResourcesProcessor(options)
|
212
212
|
}
|
213
213
|
|
214
214
|
protected constructor(options: AptosBindOptions) {
|
@@ -221,7 +221,7 @@ export class AptosAccountProcessor {
|
|
221
221
|
}
|
222
222
|
|
223
223
|
private onInterval(
|
224
|
-
handler: (resources: MoveResource[], ctx:
|
224
|
+
handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,
|
225
225
|
timeInterval: HandleInterval | undefined,
|
226
226
|
versionInterval: HandleInterval | undefined,
|
227
227
|
type: string | undefined
|
@@ -234,7 +234,7 @@ export class AptosAccountProcessor {
|
|
234
234
|
}
|
235
235
|
const timestamp = Number(data.timestampMicros)
|
236
236
|
|
237
|
-
const ctx = new
|
237
|
+
const ctx = new AptosResourcesContext(
|
238
238
|
processor.config.network,
|
239
239
|
processor.config.address,
|
240
240
|
data.version,
|
@@ -251,7 +251,7 @@ export class AptosAccountProcessor {
|
|
251
251
|
}
|
252
252
|
|
253
253
|
public onTimeInterval(
|
254
|
-
handler: (resources: MoveResource[], ctx:
|
254
|
+
handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,
|
255
255
|
timeIntervalInMinutes = 60,
|
256
256
|
backfillTimeIntervalInMinutes = 240,
|
257
257
|
type?: string
|
@@ -268,7 +268,7 @@ export class AptosAccountProcessor {
|
|
268
268
|
}
|
269
269
|
|
270
270
|
public onVersionInterval(
|
271
|
-
handler: (resources: MoveResource[], ctx:
|
271
|
+
handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,
|
272
272
|
versionInterval = 100000,
|
273
273
|
backfillVersionInterval = 400000,
|
274
274
|
typePrefix?: string
|
package/src/aptos/context.ts
CHANGED
@@ -2,7 +2,7 @@ import { Gauge } from '@sentio/sdk'
|
|
2
2
|
import { BigDecimal } from '@sentio/bigdecimal'
|
3
3
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
|
4
4
|
import {
|
5
|
-
|
5
|
+
AptosResourcesContext,
|
6
6
|
TypedMoveResource,
|
7
7
|
MoveResource,
|
8
8
|
defaultMoveCoder,
|
@@ -101,7 +101,7 @@ export class AptosDex<T> {
|
|
101
101
|
|
102
102
|
async syncPools(
|
103
103
|
resources: MoveResource[],
|
104
|
-
ctx:
|
104
|
+
ctx: AptosResourcesContext,
|
105
105
|
poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void
|
106
106
|
) {
|
107
107
|
const pools: TypedMoveResource<T>[] = defaultMoveCoder().filterAndDecodeResources(
|
package/src/aptos/index.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
export * from './move-types.js'
|
2
2
|
export type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'
|
3
3
|
export { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
4
|
-
export { AptosBaseProcessor,
|
5
|
-
export { AptosContext,
|
4
|
+
export { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js'
|
5
|
+
export { AptosContext, AptosResourcesContext } from './context.js'
|
6
6
|
export { AptosBindOptions, AptosNetwork } from './network.js'
|
7
7
|
export * from './api.js'
|
8
8
|
export { ModuleClient } from './module-client.js'
|
package/src/eth/index.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export { BaseProcessor } from './base-processor.js'
|
2
2
|
export { GenericProcessor } from './generic-processor.js'
|
3
3
|
export { BaseProcessorTemplate } from './base-processor-template.js'
|
4
|
+
export { AccountProcessor } from './account-processor.js'
|
4
5
|
export { getProvider, DummyProvider, getNetworkFromCtxOrNetworkish } from './provider.js'
|
5
6
|
export type { TypedCallTrace, Trace } from './trace.js'
|
6
7
|
export * from './eth.js'
|
package/src/sui/context.ts
CHANGED
package/src/sui/sui-plugin.ts
CHANGED
@@ -79,7 +79,7 @@ export class SuiPlugin extends Plugin {
|
|
79
79
|
})
|
80
80
|
for (const handler of processor.objectHandlers) {
|
81
81
|
const handlerId = this.suiObjectHandlers.push(handler.handler) - 1
|
82
|
-
accountConfig.
|
82
|
+
accountConfig.moveIntervalConfigs.push({
|
83
83
|
intervalConfig: {
|
84
84
|
handlerId: handlerId,
|
85
85
|
minutes: 0,
|
@@ -87,6 +87,8 @@ export class SuiPlugin extends Plugin {
|
|
87
87
|
slot: 0,
|
88
88
|
slotInterval: handler.versionInterval,
|
89
89
|
},
|
90
|
+
type: handler.type || '',
|
91
|
+
ownerType: processor.ownerType,
|
90
92
|
})
|
91
93
|
}
|
92
94
|
config.accountConfigs.push(accountConfig)
|
package/src/sui/sui-processor.ts
CHANGED
@@ -5,11 +5,12 @@ import {
|
|
5
5
|
Data_SuiObject,
|
6
6
|
ProcessResult,
|
7
7
|
HandleInterval,
|
8
|
+
MoveOnIntervalConfig_OwnerType,
|
8
9
|
} from '@sentio/protos'
|
9
10
|
import { ListStateStorage } from '@sentio/runtime'
|
10
11
|
import { SuiNetwork, getChainId } from './network.js'
|
11
12
|
import { ServerError, Status } from 'nice-grpc'
|
12
|
-
import { SuiContext,
|
13
|
+
import { SuiContext, SuiObjectsContext } from './context.js'
|
13
14
|
import { MoveEvent, SuiTransactionResponse, MoveCall, SuiMoveObject } from '@mysten/sui.js'
|
14
15
|
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'
|
15
16
|
import { getMoveCalls } from './utils.js'
|
@@ -156,26 +157,33 @@ export class SuiBaseProcessor {
|
|
156
157
|
}
|
157
158
|
|
158
159
|
class ObjectHandler {
|
160
|
+
type?: string
|
159
161
|
versionInterval?: HandleInterval
|
160
162
|
timeIntervalInMinutes?: HandleInterval
|
161
163
|
handler: (resource: Data_SuiObject) => Promise<ProcessResult>
|
162
164
|
}
|
163
165
|
|
164
|
-
export class SuiAccountProcessorState extends ListStateStorage<
|
166
|
+
export class SuiAccountProcessorState extends ListStateStorage<SuiObjectsProcessor> {
|
165
167
|
static INSTANCE = new SuiAccountProcessorState()
|
166
168
|
}
|
167
169
|
|
168
|
-
|
170
|
+
class SuiObjectsBindOptions extends SuiBindOptions {
|
171
|
+
ownerType: MoveOnIntervalConfig_OwnerType
|
172
|
+
}
|
173
|
+
|
174
|
+
export class SuiObjectsProcessor {
|
169
175
|
config: IndexConfigure
|
176
|
+
ownerType: MoveOnIntervalConfig_OwnerType
|
170
177
|
|
171
178
|
objectHandlers: ObjectHandler[] = []
|
172
179
|
|
173
|
-
static bind(options:
|
174
|
-
return new
|
180
|
+
static bind(options: SuiObjectsBindOptions): SuiObjectsProcessor {
|
181
|
+
return new SuiObjectsProcessor(options)
|
175
182
|
}
|
176
183
|
|
177
|
-
protected constructor(options:
|
184
|
+
protected constructor(options: SuiObjectsBindOptions) {
|
178
185
|
this.config = configure(options)
|
186
|
+
this.ownerType = options.ownerType
|
179
187
|
SuiAccountProcessorState.INSTANCE.addValue(this)
|
180
188
|
}
|
181
189
|
|
@@ -184,14 +192,15 @@ export class SuiAccountProcessor {
|
|
184
192
|
}
|
185
193
|
|
186
194
|
private onInterval(
|
187
|
-
handler: (resources: SuiMoveObject[], ctx:
|
195
|
+
handler: (resources: SuiMoveObject[], ctx: SuiObjectsContext) => void,
|
188
196
|
timeInterval: HandleInterval | undefined,
|
189
|
-
versionInterval: HandleInterval | undefined
|
197
|
+
versionInterval: HandleInterval | undefined,
|
198
|
+
type: string | undefined
|
190
199
|
): this {
|
191
200
|
const processor = this
|
192
201
|
this.objectHandlers.push({
|
193
202
|
handler: async function (data) {
|
194
|
-
const ctx = new
|
203
|
+
const ctx = new SuiObjectsContext(
|
195
204
|
processor.config.network,
|
196
205
|
processor.config.address,
|
197
206
|
data.slot,
|
@@ -202,14 +211,16 @@ export class SuiAccountProcessor {
|
|
202
211
|
},
|
203
212
|
timeIntervalInMinutes: timeInterval,
|
204
213
|
versionInterval: versionInterval,
|
214
|
+
type,
|
205
215
|
})
|
206
216
|
return this
|
207
217
|
}
|
208
218
|
|
209
219
|
public onTimeInterval(
|
210
|
-
handler: (objects: SuiMoveObject[], ctx:
|
220
|
+
handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => void,
|
211
221
|
timeIntervalInMinutes = 60,
|
212
|
-
backfillTimeIntervalInMinutes = 240
|
222
|
+
backfillTimeIntervalInMinutes = 240,
|
223
|
+
type?: string
|
213
224
|
): this {
|
214
225
|
return this.onInterval(
|
215
226
|
handler,
|
@@ -217,16 +228,23 @@ export class SuiAccountProcessor {
|
|
217
228
|
recentInterval: timeIntervalInMinutes,
|
218
229
|
backfillInterval: backfillTimeIntervalInMinutes,
|
219
230
|
},
|
220
|
-
undefined
|
231
|
+
undefined,
|
232
|
+
type
|
221
233
|
)
|
222
234
|
}
|
223
235
|
|
224
236
|
public onSlotInterval(
|
225
|
-
handler: (objects: SuiMoveObject[], ctx:
|
237
|
+
handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => void,
|
226
238
|
slotInterval = 100000,
|
227
|
-
backfillSlotInterval = 400000
|
239
|
+
backfillSlotInterval = 400000,
|
240
|
+
type?: string
|
228
241
|
): this {
|
229
|
-
return this.onInterval(
|
242
|
+
return this.onInterval(
|
243
|
+
handler,
|
244
|
+
undefined,
|
245
|
+
{ recentInterval: slotInterval, backfillInterval: backfillSlotInterval },
|
246
|
+
type
|
247
|
+
)
|
230
248
|
}
|
231
249
|
}
|
232
250
|
|