From 123d4665245fbe433935dd4405ded58c13b2a994 Mon Sep 17 00:00:00 2001 From: Fuyao Zhao Date: Sat, 31 Dec 2022 14:09:19 -0800 Subject: [PATCH] feat(sdk): split runtime out from sdk --- packages/base/package.json | 22 ----- packages/base/src/index.ts | 3 - packages/base/tsconfig.json | 10 --- packages/runtime/jest.config.js | 11 +++ packages/runtime/package.json | 5 +- packages/{sdk => runtime}/src/chain-config.ts | 0 packages/{sdk => runtime}/src/endpoints.ts | 5 ++ packages/runtime/src/full-service.ts | 61 +++++++++++++ .../{src => }/google/protobuf/timestamp.ts | 85 ++++++++++--------- packages/runtime/src/index.ts | 7 ++ packages/{sdk => runtime}/src/loader.ts | 0 packages/{base => runtime}/src/plugin.ts | 26 ++++-- .../{sdk => runtime}/src/processor-runner.ts | 16 ++-- packages/{sdk => runtime}/src/provider.ts | 11 +-- packages/runtime/src/service.test.ts | 48 +++++++++++ packages/{sdk => runtime}/src/service.ts | 66 ++------------ .../src/state-storage.test.ts | 0 packages/{base => runtime}/src/state.ts | 0 packages/{base => runtime}/src/utils.ts | 0 packages/runtime/tsconfig.json | 5 +- packages/sdk-aptos/src/aptos-plugin.ts | 10 +-- packages/sdk-aptos/src/aptos-processor.ts | 2 +- packages/sdk-solana/src/solana-plugin.ts | 6 +- packages/sdk-solana/src/solana-processor.ts | 2 +- packages/sdk/package.json | 19 ++--- packages/sdk/src/binds.ts | 2 +- packages/sdk/src/core/account-processor.ts | 2 +- .../sdk/src/core/base-processor-template.ts | 2 +- packages/sdk/src/core/core-plugin.ts | 39 +++++++++ packages/sdk/src/core/eth-plugin.ts | 33 ++++++- packages/sdk/src/core/event-tracker.ts | 2 +- packages/sdk/src/core/exporter.ts | 2 +- packages/sdk/src/core/generic-processor.ts | 2 +- packages/sdk/src/core/index.ts | 1 + packages/sdk/src/core/meter.ts | 2 +- packages/sdk/src/core/sui-plugin.ts | 10 +-- packages/sdk/src/core/sui-processor.ts | 2 +- packages/sdk/src/index.ts | 2 +- .../sdk/src/testing/test-processor-server.ts | 10 +-- packages/sdk/src/testing/test-provider.ts | 3 +- packages/sdk/src/types/global.d.ts | 15 ---- packages/sdk/src/utils/dex-price.test.ts | 6 +- packages/sdk/src/utils/erc20.test.ts | 5 +- packages/sdk/src/utils/price.ts | 3 +- packages/sdk/tsconfig.json | 1 - 45 files changed, 332 insertions(+), 232 deletions(-) delete mode 100644 packages/base/package.json delete mode 100644 packages/base/src/index.ts delete mode 100644 packages/base/tsconfig.json create mode 100644 packages/runtime/jest.config.js rename packages/{sdk => runtime}/src/chain-config.ts (100%) rename packages/{sdk => runtime}/src/endpoints.ts (62%) create mode 100644 packages/runtime/src/full-service.ts rename packages/runtime/src/gen/{src => }/google/protobuf/timestamp.ts (50%) create mode 100644 packages/runtime/src/index.ts rename packages/{sdk => runtime}/src/loader.ts (100%) rename packages/{base => runtime}/src/plugin.ts (61%) rename packages/{sdk => runtime}/src/processor-runner.ts (87%) rename packages/{sdk => runtime}/src/provider.ts (86%) create mode 100644 packages/runtime/src/service.test.ts rename packages/{sdk => runtime}/src/service.ts (60%) rename packages/{base => runtime}/src/state-storage.test.ts (100%) rename packages/{base => runtime}/src/state.ts (100%) rename packages/{base => runtime}/src/utils.ts (100%) create mode 100644 packages/sdk/src/core/core-plugin.ts delete mode 100644 packages/sdk/src/types/global.d.ts diff --git a/packages/base/package.json b/packages/base/package.json deleted file mode 100644 index f24f52e9af..0000000000 --- a/packages/base/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "@sentio/base", - "license": "Apache-2.0", - "version": "1.0.0", - "scripts": { - "compile": "tsc -p .", - "build": "yarn compile", - "build_all": "yarn lerna run --scope=@sentio/base build --include-dependencies", - "test": "jest" - }, - "dependencies": { - "@sentio/protos": "^1.0.0" - }, - "main": "./lib/index.js", - "types": "./lib/index.d.ts", - "module": "./lib/index.js", - "files": [ - "{lib,src}", - "!{lib,src}/tests", - "!**/*.test.{js,ts}" - ] -} diff --git a/packages/base/src/index.ts b/packages/base/src/index.ts deleted file mode 100644 index e22873340e..0000000000 --- a/packages/base/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './plugin' -export * from './state' -export * from './utils' diff --git a/packages/base/tsconfig.json b/packages/base/tsconfig.json deleted file mode 100644 index 9817516bd7..0000000000 --- a/packages/base/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "inlineSources": true, - "rootDir": "./src", - "baseUrl": "./src", - "outDir": "lib" - }, - "exclude": ["lib"] -} diff --git a/packages/runtime/jest.config.js b/packages/runtime/jest.config.js new file mode 100644 index 0000000000..059039b0ea --- /dev/null +++ b/packages/runtime/jest.config.js @@ -0,0 +1,11 @@ +/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +const { pathsToModuleNameMapper } = require('ts-jest'); +const { compilerOptions } = require('./tsconfig'); + +// TODO seems not fully ignored +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + modulePathIgnorePatterns: ["/dist/", "/lib/", "/templates/"], + moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/src/' } ) +}; diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 2ab31597e8..fc8a47376d 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -9,6 +9,7 @@ "test": "jest" }, "dependencies": { + "@sentio/protos": "^1.0.0", "@ethersproject/providers": "~5.7.0", "bignumber.js": "^9.1.0", "command-line-args": "^5.2.1", @@ -16,7 +17,6 @@ "ethers": "~5.7.1", "fs-extra": "^11.0.0", "google-protobuf": "^3.15.8", - "js-yaml": "^4.1.0", "nice-grpc": "^2.0.0", "nice-grpc-client-middleware-retry": "^2.0.1", "nice-grpc-error-details": "^0.1.4", @@ -33,7 +33,6 @@ "@types/expect": "^24.3.0", "@types/fs-extra": "^9.0.13", "@types/google-protobuf": "^3.15.6", - "@types/js-yaml": "^4.0.5", "@types/node": "^18.0.4" }, "bin": { @@ -43,7 +42,7 @@ "types": "./lib/index.d.ts", "module": "./lib/index.js", "files": [ - "{lib,src,templates}", + "{lib,src}", "!{lib,src}/tests", "!**/*.test.{js,ts}" ] diff --git a/packages/sdk/src/chain-config.ts b/packages/runtime/src/chain-config.ts similarity index 100% rename from packages/sdk/src/chain-config.ts rename to packages/runtime/src/chain-config.ts diff --git a/packages/sdk/src/endpoints.ts b/packages/runtime/src/endpoints.ts similarity index 62% rename from packages/sdk/src/endpoints.ts rename to packages/runtime/src/endpoints.ts index 0708eef145..8fbc2713ce 100644 --- a/packages/sdk/src/endpoints.ts +++ b/packages/runtime/src/endpoints.ts @@ -1,6 +1,11 @@ import { Provider } from '@ethersproject/providers' export class Endpoints { + static INSTANCE: Endpoints = new Endpoints() + + static reset() { + Endpoints.INSTANCE = new Endpoints() + } // evm providers providers = new Map() diff --git a/packages/runtime/src/full-service.ts b/packages/runtime/src/full-service.ts new file mode 100644 index 0000000000..d2dd71109f --- /dev/null +++ b/packages/runtime/src/full-service.ts @@ -0,0 +1,61 @@ +import { CallContext } from 'nice-grpc' + +// Different than the simple one which +import { + DataBinding, + HandlerType, + ProcessBindingsRequest, + ProcessConfigRequest, + ProcessorServiceImplementation, + StartRequest, +} from './gen/processor/protos/processor' + +import { Empty } from '@sentio/protos/lib/google/protobuf/empty' + +export class FullProcessorServiceImpl implements ProcessorServiceImplementation { + constructor(instance: ProcessorServiceImplementation) { + this.instance = instance + } + + instance: ProcessorServiceImplementation + + async getConfig(request: ProcessConfigRequest, context: CallContext) { + return this.instance.getConfig(request, context) + } + + async start(request: StartRequest, context: CallContext) { + return this.instance.start(request, context) + } + + async stop(request: Empty, context: CallContext) { + return this.instance.stop(request, context) + } + + async processBindings(request: ProcessBindingsRequest, options: CallContext) { + for (const binding of request.bindings) { + this.adjustDataBinding(binding) + } + return this.instance.processBindings(request, options) + } + + async *processBindingsStream(requests: AsyncIterable, context: CallContext) { + throw new Error('Not Implemented for streaming') + // y this.instance.processBindingsStream(requests, context) + } + + protected adjustDataBinding(dataBinding: DataBinding): void { + switch (dataBinding.handlerType) { + case HandlerType.UNKNOWN: + if (dataBinding.data?.ethBlock) { + if (dataBinding.data.raw.length === 0) { + // This is actually not needed in current system, just as initla test propose, move to test only + // when this is stable + dataBinding.data.raw = new TextEncoder().encode(JSON.stringify(dataBinding.data.ethBlock.block)) + } + } + break + default: + break + } + } +} diff --git a/packages/runtime/src/gen/src/google/protobuf/timestamp.ts b/packages/runtime/src/gen/google/protobuf/timestamp.ts similarity index 50% rename from packages/runtime/src/gen/src/google/protobuf/timestamp.ts rename to packages/runtime/src/gen/google/protobuf/timestamp.ts index 8fc05ee450..9342d28502 100644 --- a/packages/runtime/src/gen/src/google/protobuf/timestamp.ts +++ b/packages/runtime/src/gen/google/protobuf/timestamp.ts @@ -1,86 +1,91 @@ /* eslint-disable */ -import Long from "long"; -import _m0 from "protobufjs/minimal"; +import Long from 'long' +import _m0 from 'protobufjs/minimal' export interface Timestamp { - seconds: bigint; - nanos: number; + seconds: bigint + nanos: number } function createBaseTimestamp(): Timestamp { - return { seconds: BigInt("0"), nanos: 0 }; + return { seconds: BigInt('0'), nanos: 0 } } export const Timestamp = { encode(message: Timestamp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.seconds !== BigInt("0")) { - writer.uint32(8).int64(message.seconds.toString()); + if (message.seconds !== BigInt('0')) { + writer.uint32(8).int64(message.seconds.toString()) } if (message.nanos !== 0) { - writer.uint32(16).int32(message.nanos); + writer.uint32(16).int32(message.nanos) } - return writer; + return writer }, decode(input: _m0.Reader | Uint8Array, length?: number): Timestamp { - const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseTimestamp(); + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseTimestamp() while (reader.pos < end) { - const tag = reader.uint32(); + const tag = reader.uint32() switch (tag >>> 3) { case 1: - message.seconds = longToBigint(reader.int64() as Long); - break; + message.seconds = longToBigint(reader.int64() as Long) + break case 2: - message.nanos = reader.int32(); - break; + message.nanos = reader.int32() + break default: - reader.skipType(tag & 7); - break; + reader.skipType(tag & 7) + break } } - return message; + return message }, fromJSON(object: any): Timestamp { return { - seconds: isSet(object.seconds) ? BigInt(object.seconds) : BigInt("0"), + seconds: isSet(object.seconds) ? BigInt(object.seconds) : BigInt('0'), nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; + } }, toJSON(message: Timestamp): unknown { - const obj: any = {}; - message.seconds !== undefined && (obj.seconds = message.seconds.toString()); - message.nanos !== undefined && (obj.nanos = Math.round(message.nanos)); - return obj; + const obj: any = {} + message.seconds !== undefined && (obj.seconds = message.seconds.toString()) + message.nanos !== undefined && (obj.nanos = Math.round(message.nanos)) + return obj }, fromPartial(object: DeepPartial): Timestamp { - const message = createBaseTimestamp(); - message.seconds = object.seconds ?? BigInt("0"); - message.nanos = object.nanos ?? 0; - return message; + const message = createBaseTimestamp() + message.seconds = object.seconds ?? BigInt('0') + message.nanos = object.nanos ?? 0 + return message }, -}; +} -type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined -type DeepPartial = T extends Builtin ? T - : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> - : T extends {} ? { [K in keyof T]?: DeepPartial } - : Partial; +type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial function longToBigint(long: Long) { - return BigInt(long.toString()); + return BigInt(long.toString()) } if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any; - _m0.configure(); + _m0.util.Long = Long as any + _m0.configure() } function isSet(value: any): boolean { - return value !== null && value !== undefined; + return value !== null && value !== undefined } diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts new file mode 100644 index 0000000000..bd15bd9869 --- /dev/null +++ b/packages/runtime/src/index.ts @@ -0,0 +1,7 @@ +export * from './provider' +export * from './plugin' +export * from './state' +export * from './utils' +export * from './endpoints' +export * from './chain-config' +export * from './service' diff --git a/packages/sdk/src/loader.ts b/packages/runtime/src/loader.ts similarity index 100% rename from packages/sdk/src/loader.ts rename to packages/runtime/src/loader.ts diff --git a/packages/base/src/plugin.ts b/packages/runtime/src/plugin.ts similarity index 61% rename from packages/base/src/plugin.ts rename to packages/runtime/src/plugin.ts index c6651e3003..c368be62ed 100644 --- a/packages/base/src/plugin.ts +++ b/packages/runtime/src/plugin.ts @@ -1,11 +1,17 @@ -import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos' +import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult, StartRequest } from '@sentio/protos' -export interface Plugin { +export abstract class Plugin { name: string - supportedHandlers: HandlerType[] + supportedHandlers: HandlerType[] = [] - configure(config: ProcessConfigResponse): void - processBinding(request: DataBinding): Promise + configure(config: ProcessConfigResponse) {} + start(start: StartRequest) {} + stateDiff(config: ProcessConfigResponse): boolean { + return false + } + async processBinding(request: DataBinding): Promise { + return ProcessResult.fromPartial({}) + } } export class PluginManager { @@ -16,7 +22,6 @@ export class PluginManager { register(plugin: Plugin) { this.plugins.push(plugin) - // for (const plugin of this.plugins) { for (const handlerType of plugin.supportedHandlers) { const exsited = this.typesToPlugin.get(handlerType) if (exsited) { @@ -24,13 +29,20 @@ export class PluginManager { } this.typesToPlugin.set(handlerType, plugin) } - // } } configure(config: ProcessConfigResponse) { this.plugins.forEach((plugin) => plugin.configure(config)) } + start(start: StartRequest) { + this.plugins.forEach((plugin) => plugin.start(start)) + } + + stateDiff(config: ProcessConfigResponse): boolean { + return this.plugins.some((plugin) => plugin.stateDiff(config)) + } + processBinding(request: DataBinding): Promise { const plugin = this.typesToPlugin.get(request.handlerType) if (!plugin) { diff --git a/packages/sdk/src/processor-runner.ts b/packages/runtime/src/processor-runner.ts similarity index 87% rename from packages/sdk/src/processor-runner.ts rename to packages/runtime/src/processor-runner.ts index 3cd6d7461e..d23aecc1bb 100644 --- a/packages/sdk/src/processor-runner.ts +++ b/packages/runtime/src/processor-runner.ts @@ -12,12 +12,14 @@ import { CompressionAlgorithms } from '@grpc/grpc-js/build/src/compression-algor import { ProcessorDefinition } from '@sentio/protos' import { ProcessorServiceImpl } from './service' import { setProvider } from './provider' -import { State } from '@sentio/base' -import { load } from './loader' +import { State } from './state' import { Endpoints } from './endpoints' +import { load } from './loader' +import { FullProcessorServiceImpl } from './full-service' + State.reset() -global.ENDPOINTS = new Endpoints() +Endpoints.reset() const optionDefinitions = [ { name: 'target', type: String, defaultOption: true }, @@ -72,8 +74,8 @@ const fullPath = path.resolve(options['chains-config']) const chainsConfig = fs.readJsonSync(fullPath) setProvider(chainsConfig, options.concurrency, options['use-chainserver']) -globalThis.ENDPOINTS.chainQueryAPI = options['chainquery-server'] -globalThis.ENDPOINTS.priceFeedAPI = options['pricefeed-server'] +Endpoints.INSTANCE.chainQueryAPI = options['chainquery-server'] +Endpoints.INSTANCE.priceFeedAPI = options['pricefeed-server'] if (options.debug) { console.log('Starting Server', options) @@ -85,7 +87,9 @@ const server = createServer({ 'grpc.default_compression_algorithm': CompressionAlgorithms.gzip, }) -const service = new ProcessorServiceImpl(() => load(options.target), server.shutdown) +const baseService = new ProcessorServiceImpl(() => load(options.target), server.shutdown) +const service = new FullProcessorServiceImpl(baseService) + server.add(ProcessorDefinition, service) server.listen('0.0.0.0:' + options.port) diff --git a/packages/sdk/src/provider.ts b/packages/runtime/src/provider.ts similarity index 86% rename from packages/sdk/src/provider.ts rename to packages/runtime/src/provider.ts index ff3c212e55..c693e16e3c 100644 --- a/packages/sdk/src/provider.ts +++ b/packages/runtime/src/provider.ts @@ -3,6 +3,7 @@ import { Networkish } from '@ethersproject/networks' import PQueue from 'p-queue' import { ConnectionInfo } from '@ethersproject/web' import { ChainConfig } from './chain-config' +import { Endpoints } from './endpoints' export const DummyProvider = new StaticJsonRpcProvider(undefined, 1) @@ -12,23 +13,23 @@ export function getProvider(networkish?: Networkish): Provider { } const network = getNetwork(networkish) - if (!global.ENDPOINTS.providers) { + if (!Endpoints.INSTANCE.providers) { throw Error('Provider not set') } - const value = global.ENDPOINTS.providers.get(network.chainId) + const value = Endpoints.INSTANCE.providers.get(network.chainId) if (value === undefined) { throw Error( 'Provider not found for chain ' + network.chainId + ', configured chains: ' + - [...global.ENDPOINTS.providers.keys()].join(' ') + [...Endpoints.INSTANCE.providers.keys()].join(' ') ) } return value } export function setProvider(config: Record, concurrency = 4, useChainServer = false) { - globalThis.ENDPOINTS.providers = new Map() + Endpoints.INSTANCE.providers = new Map() for (const chainIdStr in config) { if (isNaN(Number.parseInt(chainIdStr))) { @@ -56,7 +57,7 @@ export function setProvider(config: Record, concurrency = 4 } const provider = new QueuedStaticJsonRpcProvider(rpcAddress, chainId, concurrency) - global.ENDPOINTS.providers.set(chainId, provider) + Endpoints.INSTANCE.providers.set(chainId, provider) } } diff --git a/packages/runtime/src/service.test.ts b/packages/runtime/src/service.test.ts new file mode 100644 index 0000000000..fc530ea55a --- /dev/null +++ b/packages/runtime/src/service.test.ts @@ -0,0 +1,48 @@ +import { ProcessorServiceImpl } from './service' +import { FullProcessorServiceImpl } from './full-service' +import { CallContext } from 'nice-grpc-common' +import { DataBinding, HandlerType, ProcessResult } from '@sentio/protos' +import { Plugin, PluginManager } from './plugin' +import { assert } from 'chai' + +export const TEST_CONTEXT: CallContext = {} + +// TODO use mock +class TestPlugin extends Plugin { + async processBinding(request: DataBinding): Promise { + if (request.handlerType === HandlerType.UNKNOWN) { + assert(request.data!.raw.length > 0) + } + return ProcessResult.fromPartial({}) + } + supportedHandlers = [HandlerType.UNKNOWN] +} + +describe('Test Service Compatibility', () => { + const baseService = new ProcessorServiceImpl(() => { + PluginManager.INSTANCE.plugins = [] + PluginManager.INSTANCE.register(new TestPlugin()) + }) + const service = new FullProcessorServiceImpl(baseService) + + beforeAll(async () => { + await service.start({ templateInstances: [] }, TEST_CONTEXT) + }) + + test('Check tictactoe transaction dispatch', async () => { + const binding1: DataBinding = { + data: { + raw: new Uint8Array(), + ethBlock: { + block: { + number: '0x1', + }, + }, + }, + handlerType: HandlerType.UNKNOWN, + handlerIds: [0], + } + + await service.processBindings({ bindings: [binding1] }, TEST_CONTEXT) + }) +}) diff --git a/packages/sdk/src/service.ts b/packages/runtime/src/service.ts similarity index 60% rename from packages/sdk/src/service.ts rename to packages/runtime/src/service.ts index f39638911e..f8e836749a 100644 --- a/packages/sdk/src/service.ts +++ b/packages/runtime/src/service.ts @@ -14,22 +14,12 @@ import { import { Empty } from '@sentio/protos/lib/google/protobuf/empty' -import { MetricState } from './core/meter' -import { ExporterState } from './core/exporter' -import { EventTrackerState } from './core/event-tracker' -import { ProcessorTemplateProcessorState, TemplateInstanceState } from './core/base-processor-template' - -// (Long.prototype as any).toBigInt = function() { -// return BigInt(this.toString()) -// }; -import { errorString, mergeProcessResults, PluginManager } from '@sentio/base' -import * as console from 'console' +import { PluginManager } from './plugin' +import { errorString, mergeProcessResults } from './utils' ;(BigInt.prototype as any).toJSON = function () { return this.toString() } -export const USER_PROCESSOR = 'user_processor' - export class ProcessorServiceImpl implements ProcessorServiceImplementation { private started = false private processorConfig: ProcessConfigResponse @@ -55,34 +45,6 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation { async configure() { this.processorConfig = ProcessConfigResponse.fromPartial({}) - // This syntax is to copy values instead of using references - this.processorConfig.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()] - - // part 0, prepare metrics and event tracking configs - for (const metric of MetricState.INSTANCE.getValues()) { - this.processorConfig.metricConfigs.push({ - ...metric.config, - }) - } - - for (const eventTracker of EventTrackerState.INSTANCE.getValues()) { - this.processorConfig.eventTrackingConfigs.push({ - distinctAggregationByDays: eventTracker.options.distinctByDays || [], - eventName: eventTracker.name, - retentionConfig: undefined, - totalByDay: eventTracker.options.totalByDay || false, - totalPerEntity: undefined, - unique: eventTracker.options.unique || false, - }) - } - - for (const exporter of ExporterState.INSTANCE.getValues()) { - this.processorConfig.exportConfigs.push({ - name: exporter.name, - channel: exporter.channel, - }) - } - PluginManager.INSTANCE.configure(this.processorConfig) } @@ -93,6 +55,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation { try { for (const plugin of [ + '@sentio/sdk/lib/core/core-plugin', '@sentio/sdk/lib/core/eth-plugin', '@sentio/sdk/lib/core/sui-plugin', '@sentio/sdk-aptos/lib/aptos-plugin', @@ -110,22 +73,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation { throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e)) } - for (const instance of request.templateInstances) { - const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId] - if (!template) { - throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance) - } - if (!instance.contract) { - throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance) - } - template.bind({ - name: instance.contract.name, - address: instance.contract.address, - network: Number(instance.contract.chainId), - startBlock: instance.startBlock, - endBlock: instance.endBlock, - }) - } + PluginManager.INSTANCE.start(request) + try { await this.configure() } catch (e) { @@ -152,8 +101,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation { const result = mergeProcessResults(await Promise.all(promises)) let updated = false - const t = TemplateInstanceState.INSTANCE.getValues() - if (TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) { + if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) { await this.configure() updated = true } @@ -174,7 +122,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation { for await (const request of requests) { const result = await this.processBinding(request) let updated = false - if (TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) { + if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) { await this.configure() updated = true } diff --git a/packages/base/src/state-storage.test.ts b/packages/runtime/src/state-storage.test.ts similarity index 100% rename from packages/base/src/state-storage.test.ts rename to packages/runtime/src/state-storage.test.ts diff --git a/packages/base/src/state.ts b/packages/runtime/src/state.ts similarity index 100% rename from packages/base/src/state.ts rename to packages/runtime/src/state.ts diff --git a/packages/base/src/utils.ts b/packages/runtime/src/utils.ts similarity index 100% rename from packages/base/src/utils.ts rename to packages/runtime/src/utils.ts diff --git a/packages/runtime/tsconfig.json b/packages/runtime/tsconfig.json index 9817516bd7..96c6c57057 100644 --- a/packages/runtime/tsconfig.json +++ b/packages/runtime/tsconfig.json @@ -4,7 +4,10 @@ "inlineSources": true, "rootDir": "./src", "baseUrl": "./src", - "outDir": "lib" + "outDir": "lib", + "paths": { + "@sentio/runtime": ["."] + } }, "exclude": ["lib"] } diff --git a/packages/sdk-aptos/src/aptos-plugin.ts b/packages/sdk-aptos/src/aptos-plugin.ts index 9f73002b77..f74be5beaf 100644 --- a/packages/sdk-aptos/src/aptos-plugin.ts +++ b/packages/sdk-aptos/src/aptos-plugin.ts @@ -1,4 +1,4 @@ -import { Plugin, PluginManager } from '@sentio/base' +import { Plugin, PluginManager } from '@sentio/runtime' import { AccountConfig, AptosCallHandlerConfig, @@ -10,14 +10,14 @@ import { ProcessResult, } from '@sentio/protos' -import { errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/base' +import { errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime' import { ServerError, Status } from 'nice-grpc' import { MoveResource, Transaction_UserTransaction } from 'aptos-sdk/src/generated' import { AptosAccountProcessorState, AptosProcessorState, MoveResourcesWithVersionPayload } from './aptos-processor' -export class AptosPlugin implements Plugin { +export class AptosPlugin extends Plugin { name: string = 'AptosPlugin' private aptosEventHandlers: ((event: any) => Promise)[] = [] @@ -106,7 +106,7 @@ export class AptosPlugin implements Plugin { supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT] - processBinding(request: DataBinding): Promise { + async processBinding(request: DataBinding): Promise { switch (request.handlerType) { case HandlerType.APT_CALL: return this.processAptosFunctionCall(request) @@ -114,8 +114,6 @@ export class AptosPlugin implements Plugin { return this.processAptosEvent(request) case HandlerType.APT_RESOURCE: return this.processAptosResource(request) - // case HandlerType.INSTRUCTION: - // return this.processInstruction(request) default: throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType) } diff --git a/packages/sdk-aptos/src/aptos-processor.ts b/packages/sdk-aptos/src/aptos-processor.ts index 86c98bd30b..0ecb8eab27 100644 --- a/packages/sdk-aptos/src/aptos-processor.ts +++ b/packages/sdk-aptos/src/aptos-processor.ts @@ -8,7 +8,7 @@ import { TYPE_REGISTRY, TypeRegistry } from './type-registry' import { AptosBindOptions, AptosNetwork, getChainId } from './network' import { AptosContext, AptosResourceContext } from './context' import { EventInstance } from './models' -import { ListStateStorage } from '@sentio/base' +import { ListStateStorage } from '@sentio/runtime' import { HandleInterval, ProcessResult } from '@sentio/protos' type IndexConfigure = { diff --git a/packages/sdk-solana/src/solana-plugin.ts b/packages/sdk-solana/src/solana-plugin.ts index ed3f39faa5..db5c6cc641 100644 --- a/packages/sdk-solana/src/solana-plugin.ts +++ b/packages/sdk-solana/src/solana-plugin.ts @@ -1,4 +1,4 @@ -import { Plugin, PluginManager } from '@sentio/base' +import { Plugin, PluginManager } from '@sentio/runtime' import { ContractConfig, Data_SolInstruction, @@ -7,14 +7,14 @@ import { ProcessConfigResponse, ProcessResult, } from '@sentio/protos' -import { mergeProcessResults, USER_PROCESSOR } from '@sentio/base' +import { mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime' import { ServerError, Status } from 'nice-grpc' import { SolanaProcessorState } from './solana-processor' import { Instruction as SolInstruction } from '@project-serum/anchor/dist/cjs/coder/borsh/instruction' -export class SolanaPlugin implements Plugin { +export class SolanaPlugin extends Plugin { name: string = 'SolanaPlugin' configure(config: ProcessConfigResponse): void { diff --git a/packages/sdk-solana/src/solana-processor.ts b/packages/sdk-solana/src/solana-processor.ts index 84bedd315d..28dfac5ff3 100644 --- a/packages/sdk-solana/src/solana-processor.ts +++ b/packages/sdk-solana/src/solana-processor.ts @@ -2,7 +2,7 @@ import { ProcessResult } from '@sentio/protos' import { SolanaContext } from './solana-context' import { Instruction } from '@project-serum/anchor' import { SolanaBindOptions } from './solana-options' -import { ListStateStorage } from '@sentio/base' +import { ListStateStorage } from '@sentio/runtime' import { CHAIN_IDS } from '@sentio/sdk/lib/utils/chain' type IndexConfigure = { diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 4c4869c64e..d75d46cbbf 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -7,10 +7,10 @@ "compile": "tsc -p . && cp src/utils/*.csv lib/utils", "build": "yarn gen && yarn compile", "build_all": "yarn lerna run --scope=@sentio/sdk build --include-dependencies", - "start_ts": "ts-node --files src/processor-runner.ts --log-format=json ../examples/x2y2/src/processor.ts", - "start": "ts-node --files src/processor-runner.ts ../examples/aptos/dist/lib.js", + "start_ts": "ts-node --files ../runtime/src/processor-runner.ts --log-format=json ../../examples/x2y2/src/processor.ts", + "start": "ts-node --files ../runtime/src/processor-runner.ts ../../examples/aptos/dist/lib.js", "start_js": "node lib/processor-runner.js ../examples/aptos/dist/lib.js", - "ts-start": "ts-node --files src/processor-runner.ts ./src/anyswap/src/processor.ts", + "ts-start": "ts-node --files ../runtime/src/processor-runner.ts ./src/anyswap/src/processor.ts", "test": "jest", "test-nocache": "yarn jest --clearCache && yarn jest", "gen": "yarn compile_target && yarn gen_bultin_evm", @@ -18,8 +18,8 @@ }, "dependencies": { "@ethersproject/providers": "~5.7.0", - "@sentio/base": "^1.0.0", "@sentio/cli": "^1.0.0", + "@sentio/runtime": "^1.0.0", "@sentio/protos": "^1.0.0", "@typechain/ethers-v5": "^10.0.0", "bignumber.js": "^9.1.0", @@ -27,13 +27,8 @@ "command-line-usage": "^6.1.3", "csv-parse": "^5.3.0", "ethers": "~5.7.1", - "fs-extra": "^11.0.0", "google-protobuf": "^3.15.8", - "js-yaml": "^4.1.0", "nice-grpc": "^2.0.0", - "nice-grpc-client-middleware-retry": "^2.0.1", - "nice-grpc-error-details": "^0.1.4", - "p-queue": "^6.6.2", "typechain": "^8.0.0", "winston": "^3.8.2" }, @@ -46,17 +41,13 @@ "@types/expect": "^24.3.0", "@types/fs-extra": "^9.0.13", "@types/google-protobuf": "^3.15.6", - "@types/js-yaml": "^4.0.5", "@types/node": "^18.0.4" }, - "bin": { - "processor-runner": "./lib/processor-runner.js" - }, "main": "./lib/index.js", "types": "./lib/index.d.ts", "module": "./lib/index.js", "files": [ - "{lib,src,templates}", + "{lib,src}", "!{lib,src}/tests", "!**/*.test.{js,ts}" ], diff --git a/packages/sdk/src/binds.ts b/packages/sdk/src/binds.ts index 20f92e738a..1c275b11af 100644 --- a/packages/sdk/src/binds.ts +++ b/packages/sdk/src/binds.ts @@ -3,7 +3,7 @@ import { BaseProcessor, ContractView } from './core' import { Networkish } from '@ethersproject/networks' import { getNetwork } from '@ethersproject/providers' import { BaseContract } from 'ethers' -import { MapStateStorage } from '@sentio/base' +import { MapStateStorage } from '@sentio/runtime' export class ProcessorState extends MapStateStorage> { static INSTANCE = new ProcessorState() diff --git a/packages/sdk/src/core/account-processor.ts b/packages/sdk/src/core/account-processor.ts index 6ada99f762..b8f443402d 100644 --- a/packages/sdk/src/core/account-processor.ts +++ b/packages/sdk/src/core/account-processor.ts @@ -1,4 +1,4 @@ -import { ListStateStorage } from '@sentio/base' +import { ListStateStorage } from '@sentio/runtime' import { ERC20__factory, ERC721__factory } from '../builtin/internal' import { AddressType, DummyProvider, ProcessResult } from '@sentio/sdk' import { AccountBindOptions } from './bind-options' diff --git a/packages/sdk/src/core/base-processor-template.ts b/packages/sdk/src/core/base-processor-template.ts index 7aac392313..2b98affea3 100644 --- a/packages/sdk/src/core/base-processor-template.ts +++ b/packages/sdk/src/core/base-processor-template.ts @@ -8,7 +8,7 @@ import { HandleInterval, TemplateInstance } from '@sentio/protos' import { getNetwork } from '@ethersproject/providers' import { PromiseOrVoid } from '../promise-or-void' import { Trace } from './trace' -import { ListStateStorage } from '@sentio/base' +import { ListStateStorage } from '@sentio/runtime' export class ProcessorTemplateProcessorState extends ListStateStorage< BaseProcessorTemplate> diff --git a/packages/sdk/src/core/core-plugin.ts b/packages/sdk/src/core/core-plugin.ts new file mode 100644 index 0000000000..096db1a2db --- /dev/null +++ b/packages/sdk/src/core/core-plugin.ts @@ -0,0 +1,39 @@ +import { Plugin, PluginManager } from '@sentio/runtime' +import { ProcessConfigResponse } from '@sentio/protos' + +import { MetricState } from './meter' +import { EventTrackerState } from './event-tracker' +import { ExporterState } from './exporter' + +export class CorePlugin extends Plugin { + name: string = 'CorePlugin' + + configure(config: ProcessConfigResponse): void { + // part 0, prepare metrics and event tracking configs + for (const metric of MetricState.INSTANCE.getValues()) { + config.metricConfigs.push({ + ...metric.config, + }) + } + + for (const eventTracker of EventTrackerState.INSTANCE.getValues()) { + config.eventTrackingConfigs.push({ + distinctAggregationByDays: eventTracker.options.distinctByDays || [], + eventName: eventTracker.name, + retentionConfig: undefined, + totalByDay: eventTracker.options.totalByDay || false, + totalPerEntity: undefined, + unique: eventTracker.options.unique || false, + }) + } + + for (const exporter of ExporterState.INSTANCE.getValues()) { + config.exportConfigs.push({ + name: exporter.name, + channel: exporter.channel, + }) + } + } +} + +PluginManager.INSTANCE.register(new CorePlugin()) diff --git a/packages/sdk/src/core/eth-plugin.ts b/packages/sdk/src/core/eth-plugin.ts index 40e7398fc0..9a01cd7862 100644 --- a/packages/sdk/src/core/eth-plugin.ts +++ b/packages/sdk/src/core/eth-plugin.ts @@ -1,4 +1,4 @@ -import { Plugin, PluginManager } from '@sentio/base' +import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime' import { AccountConfig, ContractConfig, @@ -8,16 +8,17 @@ import { LogHandlerConfig, ProcessConfigResponse, ProcessResult, + StartRequest, } from '@sentio/protos' -import { errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/base' import { ServerError, Status } from 'nice-grpc' import { Block, Log } from '@ethersproject/abstract-provider' import { Trace } from '@sentio/sdk' import { ProcessorState } from '../binds' import { AccountProcessorState } from './account-processor' +import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template' -export class EthPlugin implements Plugin { +export class EthPlugin extends Plugin { name: string = 'EthPlugin' private eventHandlers: ((event: Log) => Promise)[] = [] @@ -25,6 +26,9 @@ export class EthPlugin implements Plugin { private blockHandlers: ((block: Block) => Promise)[] = [] configure(config: ProcessConfigResponse): void { + // This syntax is to copy values instead of using references + config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()] + for (const processor of ProcessorState.INSTANCE.getValues()) { // If server favor incremental update this need to change // Start basic config for contract @@ -175,6 +179,29 @@ export class EthPlugin implements Plugin { } } + start(request: StartRequest) { + for (const instance of request.templateInstances) { + const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId] + if (!template) { + throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance) + } + if (!instance.contract) { + throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance) + } + template.bind({ + name: instance.contract.name, + address: instance.contract.address, + network: Number(instance.contract.chainId), + startBlock: instance.startBlock, + endBlock: instance.endBlock, + }) + } + } + + stateDiff(config: ProcessConfigResponse): boolean { + return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length + } + async processLog(request: DataBinding): Promise { if (!request.data) { throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null") diff --git a/packages/sdk/src/core/event-tracker.ts b/packages/sdk/src/core/event-tracker.ts index b8dd772f46..746d0e98ea 100644 --- a/packages/sdk/src/core/event-tracker.ts +++ b/packages/sdk/src/core/event-tracker.ts @@ -1,7 +1,7 @@ import { BaseContext } from './base-context' import { EventTrackingResult } from '@sentio/protos' import { NamedResultDescriptor } from './metadata' -import { MapStateStorage } from '@sentio/base' +import { MapStateStorage } from '@sentio/runtime' export interface Event { // The unique identifier of main identity associate with an event diff --git a/packages/sdk/src/core/exporter.ts b/packages/sdk/src/core/exporter.ts index 35806a0847..c9515a092c 100644 --- a/packages/sdk/src/core/exporter.ts +++ b/packages/sdk/src/core/exporter.ts @@ -1,7 +1,7 @@ import { BaseContext } from './base-context' import { ExportResult } from '@sentio/sdk' import { NamedResultDescriptor } from './metadata' -import { MapStateStorage } from '@sentio/base' +import { MapStateStorage } from '@sentio/runtime' export type Export = Record diff --git a/packages/sdk/src/core/generic-processor.ts b/packages/sdk/src/core/generic-processor.ts index e3e33cb9db..0a27a46044 100644 --- a/packages/sdk/src/core/generic-processor.ts +++ b/packages/sdk/src/core/generic-processor.ts @@ -2,7 +2,7 @@ import { BaseContract } from '@ethersproject/contracts' import { BoundContractView, ContractView } from './context' import { BindOptions } from './bind-options' import { BaseProcessor } from './base-processor' -import { getProvider } from '../provider' +import { getProvider } from '@sentio/runtime' import { addProcessor } from '../binds' export class GenericProcessor extends BaseProcessor< diff --git a/packages/sdk/src/core/index.ts b/packages/sdk/src/core/index.ts index bd6574c083..4e2ed356f7 100644 --- a/packages/sdk/src/core/index.ts +++ b/packages/sdk/src/core/index.ts @@ -15,3 +15,4 @@ export type { TypedCallTrace, Trace } from './trace' export { EthPlugin } from './eth-plugin' export { SuiPlugin } from './sui-plugin' +export { CorePlugin } from './core-plugin' diff --git a/packages/sdk/src/core/meter.ts b/packages/sdk/src/core/meter.ts index cd53db45bc..71f0f0f929 100644 --- a/packages/sdk/src/core/meter.ts +++ b/packages/sdk/src/core/meter.ts @@ -2,7 +2,7 @@ import { BaseContext } from './base-context' import { Numberish, toMetricValue } from './numberish' import { Labels, NamedResultDescriptor } from './metadata' import { AggregationConfig, AggregationType, MetricConfig, MetricType } from '@sentio/protos' -import { MapStateStorage } from '@sentio/base' +import { MapStateStorage } from '@sentio/runtime' export function normalizeName(name: string): string { const regex = new RegExp('![_.a-zA-Z0-9]') diff --git a/packages/sdk/src/core/sui-plugin.ts b/packages/sdk/src/core/sui-plugin.ts index 1254799b01..614860e301 100644 --- a/packages/sdk/src/core/sui-plugin.ts +++ b/packages/sdk/src/core/sui-plugin.ts @@ -1,15 +1,13 @@ -import { Plugin, PluginManager } from '@sentio/base' +import { Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime' import { ContractConfig, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos' -import { USER_PROCESSOR } from '../service' - import { ServerError, Status } from 'nice-grpc' import { CHAIN_IDS } from '../utils/chain' import { SuiProcessorState } from './sui-processor' -export class SuiPlugin implements Plugin { - name: string = 'SolanaPlugin' +export class SuiPlugin extends Plugin { + name: string = 'SuiPlugin' configure(config: ProcessConfigResponse): void { for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) { @@ -34,7 +32,7 @@ export class SuiPlugin implements Plugin { } } - supportedHandlers = [HandlerType.SUI_TRANSACTION] + supportedHandlers = [] processBinding(request: DataBinding): Promise { switch (request.handlerType) { diff --git a/packages/sdk/src/core/sui-processor.ts b/packages/sdk/src/core/sui-processor.ts index c33de7bdab..d20a97168d 100644 --- a/packages/sdk/src/core/sui-processor.ts +++ b/packages/sdk/src/core/sui-processor.ts @@ -1,6 +1,6 @@ import { SuiContext } from './context' import { ProcessResult } from '@sentio/protos' -import { ListStateStorage } from '@sentio/base' +import { ListStateStorage } from '@sentio/runtime' type IndexConfigure = { startSeqNumber: bigint diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 1fbde6d8a3..e23e70a59a 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -1,4 +1,4 @@ -export { getProvider, setProvider, DummyProvider } from './provider' +export { getProvider, setProvider, DummyProvider } from '@sentio/runtime' export { transformEtherError, EthersError } from './error' export { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds' diff --git a/packages/sdk/src/testing/test-processor-server.ts b/packages/sdk/src/testing/test-processor-server.ts index 7aae3cb285..29e9991b52 100644 --- a/packages/sdk/src/testing/test-processor-server.ts +++ b/packages/sdk/src/testing/test-processor-server.ts @@ -13,23 +13,17 @@ import { } from '@sentio/protos' import { CallContext } from 'nice-grpc-common' import { Empty } from '@sentio/protos/lib/google/protobuf/empty' -import { ChainConfig } from '../chain-config' +import { ChainConfig, ProcessorServiceImpl, setProvider, Endpoints, State } from '@sentio/runtime' import { CHAIN_MAP } from '../utils/chain' import { Block, Log } from '@ethersproject/abstract-provider' import { getNetwork, Networkish } from '@ethersproject/providers' -import { Endpoints } from '../endpoints' -import { State } from '@sentio/base' -import { ProcessorServiceImpl } from '../service' import { Trace } from '../core/trace' -import { setProvider } from '../provider' export const TEST_CONTEXT: CallContext = {} export function cleanTest() { State.reset() - if (!global.ENDPOINTS) { - global.ENDPOINTS = new Endpoints() - } + Endpoints.reset() } export class TestProcessorServer implements ProcessorServiceImplementation { diff --git a/packages/sdk/src/testing/test-provider.ts b/packages/sdk/src/testing/test-provider.ts index 7268dc0ad6..8dd6956c98 100644 --- a/packages/sdk/src/testing/test-provider.ts +++ b/packages/sdk/src/testing/test-provider.ts @@ -1,6 +1,5 @@ -import { ChainConfig } from '../chain-config' +import { ChainConfig, setProvider } from '@sentio/runtime' import { CHAIN_MAP } from '../utils/chain' -import { setProvider } from '../provider' export function loadTestProvidersFromEnv(requiredChainIds: string[] | string): boolean { const dummyConfig: Record = {} diff --git a/packages/sdk/src/types/global.d.ts b/packages/sdk/src/types/global.d.ts deleted file mode 100644 index f8bb542b8c..0000000000 --- a/packages/sdk/src/types/global.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -// import { State } from '../../../base/src/state' -import { Endpoints } from "../endpoints"; - -declare global { - // var PROCESSOR_STATE: State - var ENDPOINTS: Endpoints -} - - -// declare module "long" { -// export interface Long { -// toBigInt(): bigint; -// } -// } -// \ No newline at end of file diff --git a/packages/sdk/src/utils/dex-price.test.ts b/packages/sdk/src/utils/dex-price.test.ts index 3d41ecc19e..a4ddb926a0 100644 --- a/packages/sdk/src/utils/dex-price.test.ts +++ b/packages/sdk/src/utils/dex-price.test.ts @@ -1,13 +1,13 @@ import { EthereumDexPrice, GoerliDexPrice } from './dex-price' -import { State } from '@sentio/base' +import { State } from '@sentio/runtime' import { loadTestProvidersFromEnv } from '../testing/test-provider' import { expect } from 'chai' -import { Endpoints } from '../endpoints' +import { Endpoints } from '@sentio/runtime' describe('dex price tests', () => { State.reset() - global.ENDPOINTS = new Endpoints() + Endpoints.reset() const haveProviders = loadTestProvidersFromEnv(['1', '5']) diff --git a/packages/sdk/src/utils/erc20.test.ts b/packages/sdk/src/utils/erc20.test.ts index 8b89419763..01c3406a02 100644 --- a/packages/sdk/src/utils/erc20.test.ts +++ b/packages/sdk/src/utils/erc20.test.ts @@ -1,11 +1,10 @@ -import { State } from '@sentio/base' +import { State, Endpoints } from '@sentio/runtime' import { getERC20TokenInfo } from './token' import { loadTestProvidersFromEnv } from '../testing/test-provider' -import { Endpoints } from '../endpoints' describe('erc20 tests', () => { State.reset() - global.ENDPOINTS = new Endpoints() + Endpoints.reset() const haveProviders = loadTestProvidersFromEnv('1') diff --git a/packages/sdk/src/utils/price.ts b/packages/sdk/src/utils/price.ts index efeba4b53f..6654bb2773 100644 --- a/packages/sdk/src/utils/price.ts +++ b/packages/sdk/src/utils/price.ts @@ -1,10 +1,11 @@ import { PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/lib/service/price/protos/price' import { createChannel, createClientFactory } from 'nice-grpc' import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry' +import { Endpoints } from '@sentio/runtime' export function getPriceClient(address?: string) { if (!address) { - address = global.ENDPOINTS.priceFeedAPI + address = Endpoints.INSTANCE.priceFeedAPI } const channel = createChannel(address) diff --git a/packages/sdk/tsconfig.json b/packages/sdk/tsconfig.json index e422c4d16e..87407a6355 100644 --- a/packages/sdk/tsconfig.json +++ b/packages/sdk/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "experimentalDecorators": true, "inlineSources": true, "rootDir": "./src", "baseUrl": "./src",