@sentio/sdk 1.7.14 → 1.7.15
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/{base-processor-template.d.ts → lib/base-processor-template.d.ts} +0 -0
- package/{base-processor-template.js → lib/base-processor-template.js} +0 -0
- package/{base-processor-template.js.map → lib/base-processor-template.js.map} +0 -0
- package/{base-processor.d.ts → lib/base-processor.d.ts} +0 -0
- package/{base-processor.js → lib/base-processor.js} +0 -0
- package/{base-processor.js.map → lib/base-processor.js.map} +0 -0
- package/{bind-options.d.ts → lib/bind-options.d.ts} +0 -0
- package/{bind-options.js → lib/bind-options.js} +0 -0
- package/{bind-options.js.map → lib/bind-options.js.map} +0 -0
- package/{binds.d.ts → lib/binds.d.ts} +0 -0
- package/{binds.js → lib/binds.js} +0 -0
- package/{binds.js.map → lib/binds.js.map} +0 -0
- package/{builtin → lib/builtin}/erc20/index.d.ts +0 -0
- package/{builtin → lib/builtin}/erc20/index.js +0 -0
- package/{builtin → lib/builtin}/erc20/index.js.map +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.d.ts +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.js +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.js.map +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.js +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.js.map +0 -0
- package/{builtin → lib/builtin}/internal/common.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/common.js +0 -0
- package/{builtin → lib/builtin}/internal/common.js.map +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.js +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.js.map +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js +0 -0
- package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js.map +0 -0
- package/{builtin → lib/builtin}/internal/factories/index.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/factories/index.js +0 -0
- package/{builtin → lib/builtin}/internal/factories/index.js.map +0 -0
- package/{builtin → lib/builtin}/internal/index.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/index.js +0 -0
- package/{builtin → lib/builtin}/internal/index.js.map +0 -0
- package/{chain-config.d.ts → lib/chain-config.d.ts} +0 -0
- package/{chain-config.js → lib/chain-config.js} +0 -0
- package/{chain-config.js.map → lib/chain-config.js.map} +0 -0
- package/{cli → lib/cli}/build.d.ts +0 -0
- package/{cli → lib/cli}/build.js +0 -0
- package/{cli → lib/cli}/build.js.map +0 -0
- package/{cli → lib/cli}/cli.d.ts +0 -0
- package/{cli → lib/cli}/cli.js +0 -0
- package/{cli → lib/cli}/cli.js.map +0 -0
- package/{cli → lib/cli}/config.d.ts +0 -0
- package/{cli → lib/cli}/config.js +0 -0
- package/{cli → lib/cli}/config.js.map +0 -0
- package/{cli → lib/cli}/key.d.ts +0 -0
- package/{cli → lib/cli}/key.js +0 -0
- package/{cli → lib/cli}/key.js.map +0 -0
- package/{cli → lib/cli}/solana-code-gen.d.ts +0 -0
- package/{cli → lib/cli}/solana-code-gen.js +0 -0
- package/{cli → lib/cli}/solana-code-gen.js.map +0 -0
- package/{cli → lib/cli}/upload.d.ts +0 -0
- package/{cli → lib/cli}/upload.js +0 -0
- package/{cli → lib/cli}/upload.js.map +0 -0
- package/{cli → lib/cli}/webpack.config.js +0 -0
- package/{context.d.ts → lib/context.d.ts} +0 -0
- package/{context.js → lib/context.js} +0 -0
- package/{context.js.map → lib/context.js.map} +0 -0
- package/{contract-namer.d.ts → lib/contract-namer.d.ts} +0 -0
- package/{contract-namer.js → lib/contract-namer.js} +0 -0
- package/{contract-namer.js.map → lib/contract-namer.js.map} +0 -0
- package/{error.d.ts → lib/error.d.ts} +0 -0
- package/{error.js → lib/error.js} +0 -0
- package/{error.js.map → lib/error.js.map} +0 -0
- package/{gen → lib/gen}/builtin.d.ts +0 -0
- package/{gen → lib/gen}/builtin.js +0 -0
- package/{gen → lib/gen}/builtin.js.map +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.d.ts +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.js +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.js.map +0 -0
- package/{gen → lib/gen}/processor/protos/processor.d.ts +0 -0
- package/{gen → lib/gen}/processor/protos/processor.js +0 -0
- package/{gen → lib/gen}/processor/protos/processor.js.map +0 -0
- package/{generic-processor.d.ts → lib/generic-processor.d.ts} +0 -0
- package/{generic-processor.js → lib/generic-processor.js} +0 -0
- package/{generic-processor.js.map → lib/generic-processor.js.map} +0 -0
- package/{index.d.ts → lib/index.d.ts} +0 -0
- package/{index.js → lib/index.js} +0 -0
- package/{index.js.map → lib/index.js.map} +0 -0
- package/{meter.d.ts → lib/meter.d.ts} +0 -0
- package/{meter.js → lib/meter.js} +0 -0
- package/{meter.js.map → lib/meter.js.map} +0 -0
- package/{numberish.d.ts → lib/numberish.d.ts} +0 -0
- package/{numberish.js → lib/numberish.js} +0 -0
- package/{numberish.js.map → lib/numberish.js.map} +0 -0
- package/{numberish.test.d.ts → lib/numberish.test.d.ts} +0 -0
- package/{numberish.test.js → lib/numberish.test.js} +0 -0
- package/{numberish.test.js.map → lib/numberish.test.js.map} +0 -0
- package/{processor-runner.d.ts → lib/processor-runner.d.ts} +0 -0
- package/{processor-runner.js → lib/processor-runner.js} +0 -0
- package/{processor-runner.js.map → lib/processor-runner.js.map} +0 -0
- package/{processor-state.d.ts → lib/processor-state.d.ts} +0 -0
- package/{processor-state.js → lib/processor-state.js} +0 -0
- package/{processor-state.js.map → lib/processor-state.js.map} +0 -0
- package/{promise-or-void.d.ts → lib/promise-or-void.d.ts} +0 -0
- package/{promise-or-void.js → lib/promise-or-void.js} +0 -0
- package/{promise-or-void.js.map → lib/promise-or-void.js.map} +0 -0
- package/{provider.d.ts → lib/provider.d.ts} +0 -0
- package/{provider.js → lib/provider.js} +0 -0
- package/{provider.js.map → lib/provider.js.map} +0 -0
- package/{release.config.js → lib/release.config.js} +0 -0
- package/{service.d.ts → lib/service.d.ts} +0 -0
- package/{service.js → lib/service.js} +0 -0
- package/{service.js.map → lib/service.js.map} +0 -0
- package/{solana → lib/solana}/builtin/index.d.ts +0 -0
- package/{solana → lib/solana}/builtin/index.js +0 -0
- package/{solana → lib/solana}/builtin/index.js.map +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.d.ts +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.js +0 -0
- package/{solana → lib/solana}/builtin/spl-token-processor.js.map +0 -0
- package/{solana → lib/solana}/builtin/types.d.ts +0 -0
- package/{solana → lib/solana}/builtin/types.js +0 -0
- package/{solana → lib/solana}/builtin/types.js.map +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.d.ts +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.js +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.js.map +0 -0
- package/{solana-processor.d.ts → lib/solana-processor.d.ts} +0 -0
- package/{solana-processor.js → lib/solana-processor.js} +0 -0
- package/{solana-processor.js.map → lib/solana-processor.js.map} +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.d.ts +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js +0 -0
- package/lib/target-ethers-sentio/codegen.js.map +1 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/index.d.ts +0 -0
- package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js +0 -0
- package/lib/target-ethers-sentio/index.js.map +1 -0
- package/{test → lib/test}/codegen.test.d.ts +0 -0
- package/{test → lib/test}/codegen.test.js +1 -1
- package/{test → lib/test}/codegen.test.js.map +1 -1
- package/{test → lib/test}/erc20-template.d.ts +0 -0
- package/{test → lib/test}/erc20-template.js +0 -0
- package/{test → lib/test}/erc20-template.js.map +0 -0
- package/{test → lib/test}/erc20-template.test.d.ts +0 -0
- package/{test → lib/test}/erc20-template.test.js +0 -0
- package/{test → lib/test}/erc20-template.test.js.map +0 -0
- package/{test → lib/test}/erc20.d.ts +0 -0
- package/{test → lib/test}/erc20.js +0 -0
- package/{test → lib/test}/erc20.js.map +0 -0
- package/{test → lib/test}/erc20.test.d.ts +0 -0
- package/{test → lib/test}/erc20.test.js +0 -0
- package/{test → lib/test}/erc20.test.js.map +0 -0
- package/{test → lib/test}/generic-processor.test.d.ts +0 -0
- package/{test → lib/test}/generic-processor.test.js +0 -0
- package/{test → lib/test}/generic-processor.test.js.map +0 -0
- package/{test → lib/test}/index.d.ts +0 -0
- package/{test → lib/test}/index.js +0 -0
- package/{test → lib/test}/index.js.map +0 -0
- package/{test → lib/test}/metric-utils.d.ts +0 -0
- package/{test → lib/test}/metric-utils.js +0 -0
- package/{test → lib/test}/metric-utils.js.map +0 -0
- package/{test → lib/test}/mirrorworld.d.ts +0 -0
- package/{test → lib/test}/mirrorworld.js +0 -0
- package/{test → lib/test}/mirrorworld.js.map +0 -0
- package/{test → lib/test}/solana.test.d.ts +0 -0
- package/{test → lib/test}/solana.test.js +0 -0
- package/{test → lib/test}/solana.test.js.map +0 -0
- package/{test → lib/test}/test-processor-server.d.ts +0 -0
- package/{test → lib/test}/test-processor-server.js +0 -0
- package/{test → lib/test}/test-processor-server.js.map +0 -0
- package/{test → lib/test}/types/game_wallet.d.ts +0 -0
- package/{test → lib/test}/types/game_wallet.js +0 -0
- package/{test → lib/test}/types/game_wallet.js.map +0 -0
- package/{test → lib/test}/types/game_wallet_processor.d.ts +0 -0
- package/{test → lib/test}/types/game_wallet_processor.js +0 -0
- package/{test → lib/test}/types/game_wallet_processor.js.map +0 -0
- package/{test → lib/test}/wormhole-token-bridge.d.ts +0 -0
- package/{test → lib/test}/wormhole-token-bridge.js +0 -0
- package/{test → lib/test}/wormhole-token-bridge.js.map +0 -0
- package/{utils → lib/utils}/chainmap.d.ts +0 -0
- package/{utils → lib/utils}/chainmap.js +0 -0
- package/{utils → lib/utils}/chainmap.js.map +0 -0
- package/{utils → lib/utils}/convert.d.ts +0 -0
- package/{utils → lib/utils}/convert.js +0 -0
- package/{utils → lib/utils}/convert.js.map +0 -0
- package/{utils → lib/utils}/index.d.ts +0 -0
- package/{utils → lib/utils}/index.js +0 -0
- package/{utils → lib/utils}/index.js.map +0 -0
- package/package.json +47 -6
- package/src/abis/erc20.json +198 -0
- package/src/base-processor-template.ts +92 -0
- package/src/base-processor.ts +128 -0
- package/src/bind-options.ts +41 -0
- package/src/binds.ts +73 -0
- package/src/builtin/erc20/index.ts +6 -0
- package/src/builtin/erc20/test-utils.ts +49 -0
- package/src/builtin/internal/Erc20.ts +356 -0
- package/src/builtin/internal/common.ts +46 -0
- package/src/builtin/internal/erc20_processor.ts +295 -0
- package/src/builtin/internal/factories/Erc20__factory.ts +216 -0
- package/src/builtin/internal/factories/index.ts +4 -0
- package/src/builtin/internal/index.ts +6 -0
- package/src/chain-config.ts +6 -0
- package/src/cli/build.ts +180 -0
- package/src/cli/cli.ts +217 -0
- package/src/cli/config.ts +43 -0
- package/src/cli/key.ts +43 -0
- package/src/cli/solana-code-gen.ts +16 -0
- package/src/cli/upload.ts +86 -0
- package/src/cli/webpack.config.js +42 -0
- package/src/context.ts +93 -0
- package/src/contract-namer.ts +17 -0
- package/src/error.ts +43 -0
- package/src/gen/builtin.ts +22 -0
- package/src/gen/google/protobuf/empty.ts +70 -0
- package/src/gen/processor/protos/processor.ts +3071 -0
- package/src/generic-processor.ts +38 -0
- package/src/index.ts +19 -0
- package/src/meter.ts +122 -0
- package/src/numberish.test.ts +82 -0
- package/src/numberish.ts +99 -0
- package/src/processor-runner.ts +75 -0
- package/src/processor-state.ts +24 -0
- package/src/promise-or-void.ts +1 -0
- package/src/provider.ts +74 -0
- package/src/service.ts +434 -0
- package/src/solana/builtin/index.ts +2 -0
- package/src/solana/builtin/spl-token-processor.ts +164 -0
- package/src/solana/builtin/types.ts +268 -0
- package/src/solana/builtin/wormhole-processor.ts +178 -0
- package/src/solana-processor.ts +105 -0
- package/src/target-ethers-sentio/codegen.ts +289 -0
- package/src/target-ethers-sentio/index.ts +50 -0
- package/src/target-ethers-sentio/tsconfig.json +9 -0
- package/src/test/abis/evm/anyswapRouter.json +490 -0
- package/src/test/abis/solana/mirrorworld.json +1392 -0
- package/src/test/codegen.test.ts +26 -0
- package/src/test/erc20-template.test.ts +39 -0
- package/src/test/erc20-template.ts +25 -0
- package/src/test/erc20.test.ts +92 -0
- package/src/test/erc20.ts +48 -0
- package/src/test/generic-processor.test.ts +72 -0
- package/src/test/index.ts +1 -0
- package/src/test/metric-utils.ts +49 -0
- package/src/test/mirrorworld.ts +40 -0
- package/src/test/sentio.yaml +4 -0
- package/src/test/solana.test.ts +93 -0
- package/src/test/test-processor-server.ts +210 -0
- package/src/test/types/game_wallet.ts +1392 -0
- package/src/test/types/game_wallet_processor.ts +113 -0
- package/src/test/wormhole-token-bridge.ts +21 -0
- package/src/types/global.d.ts +17 -0
- package/src/utils/chainmap.ts +95 -0
- package/src/utils/convert.ts +6 -0
- package/src/utils/index.ts +2 -0
- package/target-ethers-sentio/codegen.js.map +0 -1
- package/target-ethers-sentio/index.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BaseContract } from '@ethersproject/contracts'
|
|
2
|
+
import { BoundContractView, ContractView } from './context'
|
|
3
|
+
import { BindOptions } from './bind-options'
|
|
4
|
+
import { BaseProcessor } from './base-processor'
|
|
5
|
+
import { getProvider } from './provider'
|
|
6
|
+
import { addProcessor, getContractName } from './binds'
|
|
7
|
+
|
|
8
|
+
export class GenericProcessor extends BaseProcessor<
|
|
9
|
+
BaseContract,
|
|
10
|
+
BoundContractView<BaseContract, ContractView<BaseContract>>
|
|
11
|
+
> {
|
|
12
|
+
eventAbi: string[]
|
|
13
|
+
constructor(eventAbi: string[], options: BindOptions) {
|
|
14
|
+
super(options)
|
|
15
|
+
this.eventAbi = eventAbi
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
protected CreateBoundContractView(): BoundContractView<BaseContract, ContractView<BaseContract>> {
|
|
19
|
+
const contract = new BaseContract(this.config.address, this.eventAbi, getProvider(this.config.network))
|
|
20
|
+
return new BoundContractView(new ContractView<BaseContract>(contract))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static bind(eventAbi: string[] | string, options: BindOptions): GenericProcessor {
|
|
24
|
+
const AbiName = 'Generic'
|
|
25
|
+
if (!Array.isArray(eventAbi)) {
|
|
26
|
+
eventAbi = [eventAbi]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// let processor = getProcessor(AbiName, options) as GenericProcessor;
|
|
30
|
+
// if (!processor) {
|
|
31
|
+
const finalOptions = Object.assign({}, options)
|
|
32
|
+
finalOptions.name = getContractName(AbiName, options.name, options.address, options.network)
|
|
33
|
+
const processor = new GenericProcessor(eventAbi, finalOptions)
|
|
34
|
+
addProcessor(AbiName, options, processor)
|
|
35
|
+
// }
|
|
36
|
+
return processor
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { BaseProcessor } from './base-processor'
|
|
2
|
+
export { GenericProcessor } from './generic-processor'
|
|
3
|
+
export { BaseProcessorTemplate } from './base-processor-template'
|
|
4
|
+
export { Context, ContractView, BoundContractView, SolanaContext } from './context'
|
|
5
|
+
export { ProcessorServiceImpl } from './service'
|
|
6
|
+
export { Counter, Meter, Gauge } from './meter'
|
|
7
|
+
export { getProvider, setProvider, DummyProvider } from './provider'
|
|
8
|
+
export { SolanaBaseProcessor } from './solana-processor'
|
|
9
|
+
export { ContractNamer } from './contract-namer'
|
|
10
|
+
export { BindOptions, SolanaBindOptions } from './bind-options'
|
|
11
|
+
export { transformEtherError } from './error'
|
|
12
|
+
export { ProcessorState } from './processor-state'
|
|
13
|
+
export { BigNumber as BigDecimal } from 'bignumber.js'
|
|
14
|
+
|
|
15
|
+
export { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'
|
|
16
|
+
|
|
17
|
+
export * from './gen/processor/protos/processor'
|
|
18
|
+
|
|
19
|
+
export { SPLTokenProcessor } from './solana/builtin'
|
package/src/meter.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { RecordMetaData } from './gen/processor/protos/processor'
|
|
2
|
+
import { Context, EthContext, SolanaContext } from './context'
|
|
3
|
+
import { toMetricValue, Numberish } from './numberish'
|
|
4
|
+
import Long from 'long'
|
|
5
|
+
|
|
6
|
+
function GetRecordMetaData(ctx: EthContext | SolanaContext, name: string, labels: Labels): RecordMetaData {
|
|
7
|
+
if (ctx instanceof Context) {
|
|
8
|
+
if (ctx.log) {
|
|
9
|
+
return {
|
|
10
|
+
contractAddress: ctx.contract.rawContract.address,
|
|
11
|
+
blockNumber: Long.fromNumber(ctx.log.blockNumber, true), // TODO need number type to be long
|
|
12
|
+
transactionIndex: ctx.log.transactionIndex,
|
|
13
|
+
logIndex: ctx.log.logIndex,
|
|
14
|
+
chainId: ctx.chainId.toString(),
|
|
15
|
+
name: name,
|
|
16
|
+
labels: labels,
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (ctx.block) {
|
|
20
|
+
return {
|
|
21
|
+
contractAddress: ctx.contract.rawContract.address,
|
|
22
|
+
blockNumber: Long.fromNumber(ctx.block.number, true),
|
|
23
|
+
transactionIndex: -1,
|
|
24
|
+
logIndex: -1,
|
|
25
|
+
chainId: ctx.chainId.toString(),
|
|
26
|
+
name: name,
|
|
27
|
+
labels: labels,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} else if (ctx instanceof SolanaContext) {
|
|
31
|
+
return {
|
|
32
|
+
contractAddress: ctx.address,
|
|
33
|
+
blockNumber: Long.ZERO, // TODO need number type to be long
|
|
34
|
+
transactionIndex: 0,
|
|
35
|
+
logIndex: 0,
|
|
36
|
+
chainId: 'SOL:mainnet', // TODO set in context
|
|
37
|
+
name: name,
|
|
38
|
+
labels: labels,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throw new Error("This can't happen")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type Labels = { [key: string]: string }
|
|
45
|
+
|
|
46
|
+
export class Counter {
|
|
47
|
+
private readonly ctx: EthContext | SolanaContext
|
|
48
|
+
private readonly name: string
|
|
49
|
+
|
|
50
|
+
constructor(name: string, ctx: EthContext | SolanaContext) {
|
|
51
|
+
this.name = name
|
|
52
|
+
this.ctx = ctx
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
add(value: Numberish, labels: Labels = {}) {
|
|
56
|
+
this.record(value, labels, true)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
sub(value: Numberish, labels: Labels = {}) {
|
|
60
|
+
this.record(value, labels, false)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private record(value: Numberish, labels: Labels, add: boolean) {
|
|
64
|
+
this.ctx.counters.push({
|
|
65
|
+
metadata: GetRecordMetaData(this.ctx, this.name, labels),
|
|
66
|
+
metricValue: toMetricValue(value),
|
|
67
|
+
add: add,
|
|
68
|
+
runtimeInfo: undefined,
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class Gauge {
|
|
74
|
+
private readonly name: string
|
|
75
|
+
private readonly ctx: EthContext | SolanaContext
|
|
76
|
+
|
|
77
|
+
constructor(name: string, ctx: EthContext | SolanaContext) {
|
|
78
|
+
this.name = name
|
|
79
|
+
this.ctx = ctx
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
record(value: Numberish, labels: Labels = {}) {
|
|
83
|
+
this.ctx.gauges.push({
|
|
84
|
+
metadata: GetRecordMetaData(this.ctx, this.name, labels),
|
|
85
|
+
metricValue: toMetricValue(value),
|
|
86
|
+
runtimeInfo: undefined,
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class Meter {
|
|
92
|
+
private readonly ctx: EthContext | SolanaContext
|
|
93
|
+
|
|
94
|
+
// TODO is map necessary since we are sending request remotely?
|
|
95
|
+
// counterMap = new Map<string, Counter>()
|
|
96
|
+
// gaugeMap = new Map<string, Gauge>()
|
|
97
|
+
|
|
98
|
+
constructor(ctx: EthContext | SolanaContext) {
|
|
99
|
+
this.ctx = ctx
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
Counter(name: string): Counter {
|
|
103
|
+
// let counter = this.counterMap.get(name)
|
|
104
|
+
|
|
105
|
+
// if (!counter) {
|
|
106
|
+
// counter = new Counter(name, this.ctx)
|
|
107
|
+
// }
|
|
108
|
+
// return counter
|
|
109
|
+
|
|
110
|
+
return new Counter(name, this.ctx)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Gauge(name: string): Gauge {
|
|
114
|
+
// let gauge = this.gaugeMap.get(name)
|
|
115
|
+
//
|
|
116
|
+
// if (!gauge) {
|
|
117
|
+
// gauge = new Gauge(name, this.ctx)
|
|
118
|
+
// }
|
|
119
|
+
// return gauge
|
|
120
|
+
return new Gauge(name, this.ctx)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { expect } from 'chai'
|
|
2
|
+
import { toBigInteger, toMetricValue } from './numberish'
|
|
3
|
+
import { webcrypto } from 'crypto'
|
|
4
|
+
import { BigNumber } from 'ethers'
|
|
5
|
+
import { performance } from 'perf_hooks'
|
|
6
|
+
import { BigInteger } from './gen/processor/protos/processor'
|
|
7
|
+
import { BigDecimal } from './index'
|
|
8
|
+
|
|
9
|
+
// TODO add test for type conversion
|
|
10
|
+
describe('Numberish tests', () => {
|
|
11
|
+
const values: bigint[] = [0n, -0n, 3815372408723498172304781320847103784n, 2132n, -18708707n, 123n << 100n]
|
|
12
|
+
|
|
13
|
+
test('big integer conversion correctness ', async () => {
|
|
14
|
+
for (const v of values) {
|
|
15
|
+
const b = toBigInteger(v)
|
|
16
|
+
const hex1 = BigIntegerToHex(b)
|
|
17
|
+
const hex2 = v.toString(16)
|
|
18
|
+
expect(hex1).equals(hex2)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('random big integer conversion correctness ', async () => {
|
|
23
|
+
for (let i = 0; i < 1000; i++) {
|
|
24
|
+
const random = webcrypto.getRandomValues(new Uint8Array(256))
|
|
25
|
+
const v = BigNumber.from(random).toBigInt()
|
|
26
|
+
const b = toBigInteger(v)
|
|
27
|
+
|
|
28
|
+
expect(BigNumber.from(b.data).eq(v)).to.equals(true)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test.skip('random big integer performance', async () => {
|
|
33
|
+
jest.setTimeout(100000)
|
|
34
|
+
jest.retryTimes(3)
|
|
35
|
+
|
|
36
|
+
let timer1 = 0
|
|
37
|
+
let timer2 = 0
|
|
38
|
+
for (let i = 0; i < 1000; i++) {
|
|
39
|
+
// Use higher value for local debugging
|
|
40
|
+
const random = webcrypto.getRandomValues(new Uint8Array(256))
|
|
41
|
+
const v = BigNumber.from(random).toBigInt()
|
|
42
|
+
|
|
43
|
+
let start = performance.now()
|
|
44
|
+
toBigInteger(v)
|
|
45
|
+
timer1 += performance.now() - start
|
|
46
|
+
|
|
47
|
+
start = performance.now()
|
|
48
|
+
v.toString(16)
|
|
49
|
+
timer2 += performance.now() - start
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.log(timer1, timer2)
|
|
53
|
+
expect(timer1).to.lessThan(timer2 * 3)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('metric values', async () => {
|
|
57
|
+
const longDec = '12.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002'
|
|
58
|
+
expect(toMetricValue(new BigDecimal(longDec)).bigDecimal == longDec)
|
|
59
|
+
|
|
60
|
+
const complexDec = '-7.350918e-428'
|
|
61
|
+
expect(toMetricValue(new BigDecimal(complexDec)).bigDecimal == complexDec)
|
|
62
|
+
|
|
63
|
+
expect(BigIntegerToBigInt(toMetricValue(new BigDecimal('100000')).bigInteger!) === 100000n)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Performance very bad
|
|
68
|
+
function BigIntegerToHex(b: BigInteger): string {
|
|
69
|
+
let res = BigNumber.from(b.data).toBigInt().toString(16)
|
|
70
|
+
if (b.negative) {
|
|
71
|
+
res = '-' + res
|
|
72
|
+
}
|
|
73
|
+
return res
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function BigIntegerToBigInt(b: BigInteger): bigint {
|
|
77
|
+
let res = BigNumber.from(b.data).toBigInt()
|
|
78
|
+
if (b.negative) {
|
|
79
|
+
res = -res
|
|
80
|
+
}
|
|
81
|
+
return res
|
|
82
|
+
}
|
package/src/numberish.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers'
|
|
2
|
+
import { BigInteger, MetricValue } from './gen/processor/protos/processor'
|
|
3
|
+
import { BigDecimal } from '.'
|
|
4
|
+
import { BN } from '@project-serum/anchor'
|
|
5
|
+
|
|
6
|
+
export type Numberish = number | BigNumber | bigint | BigDecimal //BigNumberish
|
|
7
|
+
|
|
8
|
+
export function toMetricValue(value: Numberish): MetricValue {
|
|
9
|
+
if (value instanceof BigNumber) {
|
|
10
|
+
return MetricValue.fromPartial({
|
|
11
|
+
bigInteger: toBigInteger(value.toBigInt()),
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
if (value instanceof BigDecimal) {
|
|
15
|
+
// Carefully consider the use case here
|
|
16
|
+
if (value.isInteger()) {
|
|
17
|
+
return MetricValue.fromPartial({
|
|
18
|
+
bigInteger: bigDecimalToBigInteger(value),
|
|
19
|
+
})
|
|
20
|
+
} else {
|
|
21
|
+
return MetricValue.fromPartial({
|
|
22
|
+
bigDecimal: value.toString(), // e.g. -7.350918e-428
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (BN.isBN(value)) {
|
|
27
|
+
return MetricValue.fromPartial({
|
|
28
|
+
bigInteger: bnToBigInteger(value),
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === 'bigint' || Number.isInteger(value)) {
|
|
32
|
+
return MetricValue.fromPartial({
|
|
33
|
+
bigInteger: toBigInteger(value),
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return MetricValue.fromPartial({
|
|
38
|
+
doubleValue: Number(value),
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
function bigDecimalToBigInteger(a: BigDecimal): BigInteger {
|
|
42
|
+
const negative = a.isNegative()
|
|
43
|
+
if (negative) {
|
|
44
|
+
a = a.abs()
|
|
45
|
+
}
|
|
46
|
+
return hexToBigInteger(a.toString(16), negative)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function bnToBigInteger(a: BN): BigInteger {
|
|
50
|
+
const negative = a.isNeg()
|
|
51
|
+
if (negative) {
|
|
52
|
+
a = a.abs()
|
|
53
|
+
}
|
|
54
|
+
return hexToBigInteger(a.toString(16), negative)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function intToBigInteger(a: bigint | number): BigInteger {
|
|
58
|
+
const negative = a < 0
|
|
59
|
+
if (negative) {
|
|
60
|
+
a = -a
|
|
61
|
+
}
|
|
62
|
+
return hexToBigInteger(a.toString(16), negative)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function toBigInteger(a: Numberish): BigInteger {
|
|
66
|
+
if (a instanceof BigDecimal) {
|
|
67
|
+
return bigDecimalToBigInteger(a)
|
|
68
|
+
}
|
|
69
|
+
if (a instanceof BN) {
|
|
70
|
+
return bnToBigInteger(a)
|
|
71
|
+
}
|
|
72
|
+
if (a instanceof BigNumber) {
|
|
73
|
+
return intToBigInteger(a.toBigInt())
|
|
74
|
+
}
|
|
75
|
+
return intToBigInteger(a)
|
|
76
|
+
|
|
77
|
+
// Following code is actually very slow
|
|
78
|
+
// while (a > 0) {
|
|
79
|
+
// const d = a & 0xffn
|
|
80
|
+
// a >>= 8n
|
|
81
|
+
// value.push(Number(d))
|
|
82
|
+
// }
|
|
83
|
+
//
|
|
84
|
+
// return {
|
|
85
|
+
// negative, value: new Uint8Array(value.reverse()),
|
|
86
|
+
// }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function hexToBigInteger(hex: string, negative: boolean): BigInteger {
|
|
90
|
+
if (hex.length % 2 === 1) {
|
|
91
|
+
hex = '0' + hex
|
|
92
|
+
}
|
|
93
|
+
const buffer = Buffer.from(hex, 'hex')
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
negative: negative,
|
|
97
|
+
data: new Uint8Array(buffer),
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import commandLineArgs from 'command-line-args'
|
|
4
|
+
import { createServer } from 'nice-grpc'
|
|
5
|
+
import { ProcessorDefinition } from './gen/processor/protos/processor'
|
|
6
|
+
import { ProcessorServiceImpl } from './service'
|
|
7
|
+
import { setProvider } from './provider'
|
|
8
|
+
|
|
9
|
+
import path from 'path'
|
|
10
|
+
import fs from 'fs-extra'
|
|
11
|
+
import { ProcessorState } from './processor-state'
|
|
12
|
+
|
|
13
|
+
global.sentio_sdk = require('.')
|
|
14
|
+
global.PROCESSOR_STATE = new ProcessorState()
|
|
15
|
+
|
|
16
|
+
function tryRequire(name: string): { module: any; name: string; path: string } | undefined {
|
|
17
|
+
const req = eval('require')
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
let path: string
|
|
21
|
+
try {
|
|
22
|
+
path = req.resolve(name, { paths: [process.cwd()] })
|
|
23
|
+
} catch {
|
|
24
|
+
path = req.resolve(name)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const module = { module: req(path), name, path }
|
|
28
|
+
console.log('Load successfully: ', name)
|
|
29
|
+
return module
|
|
30
|
+
} catch (err) {
|
|
31
|
+
if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
|
|
32
|
+
// this error is expected
|
|
33
|
+
console.log("Couldn't load (expected): ", name)
|
|
34
|
+
return undefined
|
|
35
|
+
} else {
|
|
36
|
+
throw err
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const optionDefinitions = [
|
|
42
|
+
{ name: 'target', type: String, defaultOption: true },
|
|
43
|
+
{ name: 'port', alias: 'p', type: String, defaultValue: '4000' },
|
|
44
|
+
{ name: 'concurrency', type: Number, defaultValue: 4 },
|
|
45
|
+
{ name: 'use-chainserver', type: Boolean, defaultValue: false },
|
|
46
|
+
{
|
|
47
|
+
name: 'chains-config',
|
|
48
|
+
alias: 'c',
|
|
49
|
+
type: String,
|
|
50
|
+
defaultValue: 'chains-config.json',
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
const options = commandLineArgs(optionDefinitions, { partial: true })
|
|
55
|
+
|
|
56
|
+
console.log('loading', options.target)
|
|
57
|
+
|
|
58
|
+
const fullPath = path.resolve(options['chains-config'])
|
|
59
|
+
const chainsConfig = fs.readJsonSync(fullPath)
|
|
60
|
+
|
|
61
|
+
setProvider(chainsConfig, options.concurrency, options['use-chainserver'])
|
|
62
|
+
|
|
63
|
+
tryRequire(options.target)
|
|
64
|
+
|
|
65
|
+
console.log('Start Server', options)
|
|
66
|
+
|
|
67
|
+
console.log(global.PROCESSOR_STATE.processors.length, ' processors loaded')
|
|
68
|
+
console.log(global.PROCESSOR_STATE.solanaProcessors.length, ' solana processors loaded')
|
|
69
|
+
|
|
70
|
+
const server = createServer()
|
|
71
|
+
|
|
72
|
+
const service = new ProcessorServiceImpl(server.shutdown)
|
|
73
|
+
server.add(ProcessorDefinition, service)
|
|
74
|
+
|
|
75
|
+
server.listen('0.0.0.0:' + options.port)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseProcessor } from './base-processor'
|
|
2
|
+
import { BaseContract } from 'ethers'
|
|
3
|
+
import { BoundContractView, ContractView } from './context'
|
|
4
|
+
import { BaseProcessorTemplate } from './base-processor-template'
|
|
5
|
+
import { TemplateInstance } from './gen/processor/protos/processor'
|
|
6
|
+
import { Provider } from '@ethersproject/providers'
|
|
7
|
+
import { SolanaBaseProcessor } from './solana-processor'
|
|
8
|
+
|
|
9
|
+
export class ProcessorState {
|
|
10
|
+
// from abiName_address_chainId => contract wrapper
|
|
11
|
+
contracts = new Map<string, ContractView<BaseContract>>()
|
|
12
|
+
// all evm processors
|
|
13
|
+
processors: BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>[] = []
|
|
14
|
+
// from abiName_options to contracts
|
|
15
|
+
processorMap = new Map<string, BaseProcessor<any, any>>()
|
|
16
|
+
// evm providers
|
|
17
|
+
providers = new Map<number, Provider>()
|
|
18
|
+
// evm processor templates
|
|
19
|
+
templates: BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>[] = []
|
|
20
|
+
// evm processor template instances spec
|
|
21
|
+
templatesInstances: TemplateInstance[] = []
|
|
22
|
+
|
|
23
|
+
solanaProcessors: SolanaBaseProcessor[] = []
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type PromiseOrVoid = void | Promise<any>
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getNetwork, Provider, StaticJsonRpcProvider } from '@ethersproject/providers'
|
|
2
|
+
import { Networkish } from '@ethersproject/networks'
|
|
3
|
+
import PQueue from 'p-queue'
|
|
4
|
+
import { ConnectionInfo } from '@ethersproject/web'
|
|
5
|
+
import { ChainConfig } from './chain-config'
|
|
6
|
+
|
|
7
|
+
export const DummyProvider = new StaticJsonRpcProvider(undefined, 1)
|
|
8
|
+
|
|
9
|
+
export function getProvider(networkish?: Networkish): Provider {
|
|
10
|
+
if (!networkish) {
|
|
11
|
+
networkish = 1
|
|
12
|
+
}
|
|
13
|
+
const network = getNetwork(networkish)
|
|
14
|
+
|
|
15
|
+
if (!global.PROCESSOR_STATE.providers) {
|
|
16
|
+
throw Error('Provider not set')
|
|
17
|
+
}
|
|
18
|
+
const value = global.PROCESSOR_STATE.providers.get(network.chainId)
|
|
19
|
+
if (value === undefined) {
|
|
20
|
+
throw Error(
|
|
21
|
+
'Provider not found for chain ' +
|
|
22
|
+
network.chainId +
|
|
23
|
+
', configured chains: ' +
|
|
24
|
+
[...global.PROCESSOR_STATE.providers.keys()].join(' ')
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
return value
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function setProvider(config: Record<string, ChainConfig>, concurrency = 4, useChainServer = false) {
|
|
31
|
+
global.PROCESSOR_STATE.providers = new Map<number, Provider>()
|
|
32
|
+
|
|
33
|
+
for (const chainIdStr in config) {
|
|
34
|
+
if (isNaN(Number.parseInt(chainIdStr))) {
|
|
35
|
+
continue
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const chainConfig = config[chainIdStr]
|
|
39
|
+
const chainId = Number(chainIdStr)
|
|
40
|
+
|
|
41
|
+
// let providers: StaticJsonRpcProvider[] = []
|
|
42
|
+
// for (const http of chainConfig.Https) {
|
|
43
|
+
// providers.push(new StaticJsonRpcProvider(http, chainId))
|
|
44
|
+
// }
|
|
45
|
+
// random shuffle
|
|
46
|
+
// providers = providers.sort(() => Math.random() - 0.5)
|
|
47
|
+
|
|
48
|
+
// const provider = new FallbackProvider(providers)
|
|
49
|
+
|
|
50
|
+
let rpcAddress = ''
|
|
51
|
+
if (useChainServer && chainConfig.ChainServer) {
|
|
52
|
+
rpcAddress = chainConfig.ChainServer
|
|
53
|
+
} else {
|
|
54
|
+
const idx = Math.floor(Math.random() * chainConfig.Https.length)
|
|
55
|
+
rpcAddress = chainConfig.Https[idx]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const provider = new QueuedStaticJsonRpcProvider(rpcAddress, chainId, concurrency)
|
|
59
|
+
global.PROCESSOR_STATE.providers.set(chainId, provider)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
class QueuedStaticJsonRpcProvider extends StaticJsonRpcProvider {
|
|
64
|
+
executor: PQueue
|
|
65
|
+
|
|
66
|
+
constructor(url: ConnectionInfo | string, network: Networkish, concurrency: number) {
|
|
67
|
+
super(url, network)
|
|
68
|
+
this.executor = new PQueue({ concurrency: concurrency })
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
send(method: string, params: Array<any>): Promise<any> {
|
|
72
|
+
return this.executor.add(() => super.send(method, params))
|
|
73
|
+
}
|
|
74
|
+
}
|