@sentio/sdk 1.7.13 → 1.7.16
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/lib/base-processor-template.js.map +1 -0
- package/{base-processor.d.ts → lib/base-processor.d.ts} +0 -0
- package/{base-processor.js → lib/base-processor.js} +0 -0
- package/lib/base-processor.js.map +1 -0
- package/{bind-options.d.ts → lib/bind-options.d.ts} +0 -0
- package/{bind-options.js → lib/bind-options.js} +0 -0
- package/lib/bind-options.js.map +1 -0
- package/{binds.d.ts → lib/binds.d.ts} +0 -0
- package/{binds.js → lib/binds.js} +0 -0
- package/lib/binds.js.map +1 -0
- package/{builtin → lib/builtin}/erc20/index.d.ts +0 -0
- package/{builtin → lib/builtin}/erc20/index.js +0 -0
- package/lib/builtin/erc20/index.js.map +1 -0
- package/{builtin → lib/builtin}/erc20/test-utils.d.ts +0 -0
- package/{builtin → lib/builtin}/erc20/test-utils.js +0 -0
- package/lib/builtin/erc20/test-utils.js.map +1 -0
- package/{builtin → lib/builtin}/internal/Erc20.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/Erc20.js +0 -0
- package/lib/builtin/internal/Erc20.js.map +1 -0
- package/{builtin → lib/builtin}/internal/common.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/common.js +0 -0
- package/lib/builtin/internal/common.js.map +1 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/erc20_processor.js +0 -0
- package/lib/builtin/internal/erc20_processor.js.map +1 -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/lib/builtin/internal/factories/Erc20__factory.js.map +1 -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 +1 -1
- package/{builtin → lib/builtin}/internal/index.d.ts +0 -0
- package/{builtin → lib/builtin}/internal/index.js +0 -0
- package/lib/builtin/internal/index.js.map +1 -0
- package/{chain-config.d.ts → lib/chain-config.d.ts} +0 -0
- package/{chain-config.js → lib/chain-config.js} +0 -0
- package/lib/chain-config.js.map +1 -0
- package/{cli → lib/cli}/build.d.ts +0 -0
- package/{cli → lib/cli}/build.js +0 -0
- package/lib/cli/build.js.map +1 -0
- package/{cli → lib/cli}/cli.d.ts +0 -0
- package/{cli → lib/cli}/cli.js +0 -0
- package/lib/cli/cli.js.map +1 -0
- package/{cli → lib/cli}/config.d.ts +0 -0
- package/{cli → lib/cli}/config.js +0 -0
- package/lib/cli/config.js.map +1 -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 +1 -1
- 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 +1 -1
- package/{cli → lib/cli}/upload.d.ts +0 -0
- package/{cli → lib/cli}/upload.js +0 -0
- package/{cli → lib/cli}/upload.js.map +1 -1
- 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/lib/context.js.map +1 -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} +1 -1
- package/{error.d.ts → lib/error.d.ts} +0 -0
- package/{error.js → lib/error.js} +0 -0
- package/lib/error.js.map +1 -0
- package/{gen → lib/gen}/builtin.d.ts +0 -0
- package/{gen → lib/gen}/builtin.js +0 -0
- package/lib/gen/builtin.js.map +1 -0
- package/{gen → lib/gen}/google/protobuf/empty.d.ts +0 -0
- package/{gen → lib/gen}/google/protobuf/empty.js +0 -0
- package/lib/gen/google/protobuf/empty.js.map +1 -0
- package/{gen → lib/gen}/processor/protos/processor.d.ts +0 -0
- package/{gen → lib/gen}/processor/protos/processor.js +0 -0
- package/lib/gen/processor/protos/processor.js.map +1 -0
- package/{generic-processor.d.ts → lib/generic-processor.d.ts} +0 -0
- package/{generic-processor.js → lib/generic-processor.js} +0 -0
- package/lib/generic-processor.js.map +1 -0
- package/{index.d.ts → lib/index.d.ts} +0 -0
- package/{index.js → lib/index.js} +0 -0
- package/lib/index.js.map +1 -0
- package/lib/loader.d.ts +5 -0
- package/lib/loader.js +30 -0
- package/lib/loader.js.map +1 -0
- package/{meter.d.ts → lib/meter.d.ts} +0 -0
- package/{meter.js → lib/meter.js} +0 -0
- package/lib/meter.js.map +1 -0
- package/{numberish.d.ts → lib/numberish.d.ts} +0 -0
- package/{numberish.js → lib/numberish.js} +0 -0
- package/lib/numberish.js.map +1 -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} +1 -1
- package/{processor-runner.d.ts → lib/processor-runner.d.ts} +0 -0
- package/{processor-runner.js → lib/processor-runner.js} +2 -27
- package/lib/processor-runner.js.map +1 -0
- package/{processor-state.d.ts → lib/processor-state.d.ts} +0 -0
- package/{processor-state.js → lib/processor-state.js} +0 -0
- package/lib/processor-state.js.map +1 -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/lib/promise-or-void.js.map +1 -0
- package/{provider.d.ts → lib/provider.d.ts} +0 -0
- package/{provider.js → lib/provider.js} +0 -0
- package/lib/provider.js.map +1 -0
- package/{release.config.js → lib/release.config.js} +0 -0
- package/{service.d.ts → lib/service.d.ts} +2 -1
- package/{service.js → lib/service.js} +6 -3
- package/lib/service.js.map +1 -0
- package/{solana → lib/solana}/builtin/index.d.ts +0 -0
- package/{solana → lib/solana}/builtin/index.js +0 -0
- package/lib/solana/builtin/index.js.map +1 -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/lib/solana/builtin/spl-token-processor.js.map +1 -0
- package/{solana → lib/solana}/builtin/types.d.ts +0 -0
- package/{solana → lib/solana}/builtin/types.js +0 -0
- package/lib/solana/builtin/types.js.map +1 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.d.ts +0 -0
- package/{solana → lib/solana}/builtin/wormhole-processor.js +0 -0
- package/lib/solana/builtin/wormhole-processor.js.map +1 -0
- package/{solana-processor.d.ts → lib/solana-processor.d.ts} +0 -0
- package/{solana-processor.js → lib/solana-processor.js} +0 -0
- package/lib/solana-processor.js.map +1 -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/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js.map +0 -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/{target-ethers-sentio → lib/target-ethers-sentio}/index.js.map +0 -0
- package/{test → lib/test}/codegen.test.d.ts +0 -0
- package/{test → lib/test}/codegen.test.js +1 -1
- package/lib/test/codegen.test.js.map +1 -0
- package/{test → lib/test}/erc20-template.d.ts +0 -0
- package/{test → lib/test}/erc20-template.js +0 -0
- package/lib/test/erc20-template.js.map +1 -0
- package/{test → lib/test}/erc20-template.test.d.ts +0 -0
- package/{test → lib/test}/erc20-template.test.js +1 -3
- package/lib/test/erc20-template.test.js.map +1 -0
- package/{test → lib/test}/erc20.d.ts +0 -0
- package/{test → lib/test}/erc20.js +0 -0
- package/lib/test/erc20.js.map +1 -0
- package/{test → lib/test}/erc20.test.d.ts +0 -0
- package/{test → lib/test}/erc20.test.js +1 -3
- package/lib/test/erc20.test.js.map +1 -0
- package/{test → lib/test}/generic-processor.test.d.ts +0 -0
- package/{test → lib/test}/generic-processor.test.js +14 -4
- package/lib/test/generic-processor.test.js.map +1 -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 +1 -1
- package/{test → lib/test}/metric-utils.d.ts +0 -0
- package/{test → lib/test}/metric-utils.js +0 -0
- package/lib/test/metric-utils.js.map +1 -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 +1 -1
- package/{test → lib/test}/solana.test.d.ts +0 -0
- package/{test → lib/test}/solana.test.js +3 -3
- package/lib/test/solana.test.js.map +1 -0
- package/{test → lib/test}/test-processor-server.d.ts +1 -1
- package/{test → lib/test}/test-processor-server.js +3 -8
- package/lib/test/test-processor-server.js.map +1 -0
- package/{test → lib/test}/types/game_wallet.d.ts +0 -0
- package/{test → lib/test}/types/game_wallet.js +0 -0
- package/lib/test/types/game_wallet.js.map +1 -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/lib/test/types/game_wallet_processor.js.map +1 -0
- package/{test → lib/test}/wormhole-token-bridge.d.ts +0 -0
- package/{test → lib/test}/wormhole-token-bridge.js +0 -0
- package/lib/test/wormhole-token-bridge.js.map +1 -0
- package/{utils → lib/utils}/chainmap.d.ts +0 -0
- package/{utils → lib/utils}/chainmap.js +0 -0
- package/lib/utils/chainmap.js.map +1 -0
- package/{utils → lib/utils}/convert.d.ts +0 -0
- package/{utils → lib/utils}/convert.js +0 -0
- package/lib/utils/convert.js.map +1 -0
- package/{utils → lib/utils}/index.d.ts +0 -0
- package/{utils → lib/utils}/index.js +0 -0
- package/lib/utils/index.js.map +1 -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/loader.ts +24 -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 +49 -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 +439 -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 +37 -0
- package/src/test/erc20-template.ts +25 -0
- package/src/test/erc20.test.ts +90 -0
- package/src/test/erc20.ts +48 -0
- package/src/test/generic-processor.test.ts +70 -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 +205 -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/base-processor-template.js.map +0 -1
- package/base-processor.js.map +0 -1
- package/bind-options.js.map +0 -1
- package/binds.js.map +0 -1
- package/builtin/erc20/index.js.map +0 -1
- package/builtin/erc20/test-utils.js.map +0 -1
- package/builtin/internal/Erc20.js.map +0 -1
- package/builtin/internal/common.js.map +0 -1
- package/builtin/internal/erc20_processor.js.map +0 -1
- package/builtin/internal/factories/Erc20__factory.js.map +0 -1
- package/builtin/internal/index.js.map +0 -1
- package/chain-config.js.map +0 -1
- package/cli/build.js.map +0 -1
- package/cli/cli.js.map +0 -1
- package/cli/config.js.map +0 -1
- package/context.js.map +0 -1
- package/error.js.map +0 -1
- package/gen/builtin.js.map +0 -1
- package/gen/google/protobuf/empty.js.map +0 -1
- package/gen/processor/protos/processor.js.map +0 -1
- package/generic-processor.js.map +0 -1
- package/index.js.map +0 -1
- package/meter.js.map +0 -1
- package/numberish.js.map +0 -1
- package/processor-runner.js.map +0 -1
- package/processor-state.js.map +0 -1
- package/promise-or-void.js.map +0 -1
- package/provider.js.map +0 -1
- package/service.js.map +0 -1
- package/solana/builtin/index.js.map +0 -1
- package/solana/builtin/spl-token-processor.js.map +0 -1
- package/solana/builtin/types.js.map +0 -1
- package/solana/builtin/wormhole-processor.js.map +0 -1
- package/solana-processor.js.map +0 -1
- package/test/codegen.test.js.map +0 -1
- package/test/erc20-template.js.map +0 -1
- package/test/erc20-template.test.js.map +0 -1
- package/test/erc20.js.map +0 -1
- package/test/erc20.test.js.map +0 -1
- package/test/generic-processor.test.js.map +0 -1
- package/test/metric-utils.js.map +0 -1
- package/test/solana.test.js.map +0 -1
- package/test/test-processor-server.js.map +0 -1
- package/test/types/game_wallet.js.map +0 -1
- package/test/types/game_wallet_processor.js.map +0 -1
- package/test/wormhole-token-bridge.js.map +0 -1
- package/utils/chainmap.js.map +0 -1
- package/utils/convert.js.map +0 -1
- package/utils/index.js.map +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { BoundContractView, Context, ContractView } from './context'
|
|
2
|
+
import { Block } from '@ethersproject/abstract-provider'
|
|
3
|
+
import { BaseContract, EventFilter } from 'ethers'
|
|
4
|
+
import { Event } from '@ethersproject/contracts'
|
|
5
|
+
import { BaseProcessor } from './base-processor'
|
|
6
|
+
import { BindOptions, getOptionsSignature } from './bind-options'
|
|
7
|
+
import { TemplateInstance } from './gen/processor/protos/processor'
|
|
8
|
+
import Long from 'long'
|
|
9
|
+
import { getNetwork } from '@ethersproject/providers'
|
|
10
|
+
import { PromiseOrVoid } from './promise-or-void'
|
|
11
|
+
|
|
12
|
+
export abstract class BaseProcessorTemplate<
|
|
13
|
+
TContract extends BaseContract,
|
|
14
|
+
TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>
|
|
15
|
+
> {
|
|
16
|
+
id: number
|
|
17
|
+
binds = new Set<string>()
|
|
18
|
+
blockHandlers: ((block: Block, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid)[] = []
|
|
19
|
+
eventHandlers: {
|
|
20
|
+
handler: (event: Event, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid
|
|
21
|
+
filter: EventFilter | EventFilter[]
|
|
22
|
+
}[] = []
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
this.id = global.PROCESSOR_STATE.templates.length
|
|
26
|
+
global.PROCESSOR_STATE.templates.push(this)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public bind(options: BindOptions) {
|
|
30
|
+
const sig = getOptionsSignature(options)
|
|
31
|
+
if (this.binds.has(sig)) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
this.binds.add(sig)
|
|
35
|
+
|
|
36
|
+
const processor = this.bindInternal(options)
|
|
37
|
+
|
|
38
|
+
for (const eh of this.eventHandlers) {
|
|
39
|
+
processor.onEvent(eh.handler, eh.filter)
|
|
40
|
+
}
|
|
41
|
+
for (const bh of this.blockHandlers) {
|
|
42
|
+
processor.onBlock(bh)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const instance: TemplateInstance = {
|
|
46
|
+
templateId: this.id,
|
|
47
|
+
contract: {
|
|
48
|
+
address: options.address,
|
|
49
|
+
name: options.name || '',
|
|
50
|
+
chainId: options.network ? getNetwork(options.network).chainId.toString() : '1',
|
|
51
|
+
abi: '',
|
|
52
|
+
},
|
|
53
|
+
startBlock: Long.ZERO,
|
|
54
|
+
endBlock: Long.ZERO,
|
|
55
|
+
}
|
|
56
|
+
if (options.startBlock) {
|
|
57
|
+
if (typeof options.startBlock === 'number') {
|
|
58
|
+
instance.startBlock = Long.fromNumber(options.startBlock)
|
|
59
|
+
} else {
|
|
60
|
+
instance.startBlock = options.startBlock
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (options.endBlock) {
|
|
64
|
+
if (typeof options.endBlock === 'number') {
|
|
65
|
+
instance.endBlock = Long.fromNumber(options.endBlock)
|
|
66
|
+
} else {
|
|
67
|
+
instance.endBlock = options.endBlock
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
global.PROCESSOR_STATE.templatesInstances.push(instance)
|
|
71
|
+
|
|
72
|
+
return processor
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public onEvent(
|
|
76
|
+
handler: (event: Event, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid,
|
|
77
|
+
filter: EventFilter | EventFilter[]
|
|
78
|
+
) {
|
|
79
|
+
this.eventHandlers.push({
|
|
80
|
+
handler: handler,
|
|
81
|
+
filter: filter,
|
|
82
|
+
})
|
|
83
|
+
return this
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public onBlock(handler: (block: Block, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid) {
|
|
87
|
+
this.blockHandlers.push(handler)
|
|
88
|
+
return this
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>
|
|
92
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Event } from '@ethersproject/contracts'
|
|
2
|
+
import { BytesLike } from '@ethersproject/bytes'
|
|
3
|
+
import { Block, Log, getNetwork } from '@ethersproject/providers'
|
|
4
|
+
import { BaseContract, EventFilter } from '@ethersproject/contracts'
|
|
5
|
+
import Long from 'long'
|
|
6
|
+
|
|
7
|
+
import { BoundContractView, Context, ContractView } from './context'
|
|
8
|
+
import { O11yResult } from './gen/processor/protos/processor'
|
|
9
|
+
import { BindInternalOptions, BindOptions } from './bind-options'
|
|
10
|
+
import { PromiseOrVoid } from './promise-or-void'
|
|
11
|
+
|
|
12
|
+
export class EventsHandler {
|
|
13
|
+
filters: EventFilter[]
|
|
14
|
+
handler: (event: Log) => Promise<O11yResult>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export abstract class BaseProcessor<
|
|
18
|
+
TContract extends BaseContract,
|
|
19
|
+
TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>
|
|
20
|
+
> {
|
|
21
|
+
blockHandlers: ((block: Block) => Promise<O11yResult>)[] = []
|
|
22
|
+
eventHandlers: EventsHandler[] = []
|
|
23
|
+
|
|
24
|
+
name: string
|
|
25
|
+
config: BindInternalOptions
|
|
26
|
+
|
|
27
|
+
constructor(config: BindOptions) {
|
|
28
|
+
this.config = {
|
|
29
|
+
address: config.address,
|
|
30
|
+
name: config.name || '',
|
|
31
|
+
network: config.network ? config.network : 1,
|
|
32
|
+
startBlock: new Long(0),
|
|
33
|
+
}
|
|
34
|
+
if (config.startBlock) {
|
|
35
|
+
if (typeof config.startBlock === 'number') {
|
|
36
|
+
this.config.startBlock = Long.fromNumber(config.startBlock)
|
|
37
|
+
} else {
|
|
38
|
+
this.config.startBlock = config.startBlock
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (config.endBlock) {
|
|
42
|
+
if (typeof config.endBlock === 'number') {
|
|
43
|
+
this.config.endBlock = Long.fromNumber(config.endBlock)
|
|
44
|
+
} else {
|
|
45
|
+
this.config.endBlock = config.endBlock
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected abstract CreateBoundContractView(): TBoundContractView
|
|
51
|
+
|
|
52
|
+
public getChainId(): number {
|
|
53
|
+
return getNetwork(this.config.network).chainId
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public onEvent(
|
|
57
|
+
handler: (event: Event, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid,
|
|
58
|
+
filter: EventFilter | EventFilter[]
|
|
59
|
+
) {
|
|
60
|
+
const chainId = this.getChainId()
|
|
61
|
+
|
|
62
|
+
let _filters: EventFilter[] = []
|
|
63
|
+
|
|
64
|
+
if (Array.isArray(filter)) {
|
|
65
|
+
_filters = filter
|
|
66
|
+
} else {
|
|
67
|
+
_filters.push(filter)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const contractView = this.CreateBoundContractView()
|
|
71
|
+
this.eventHandlers.push({
|
|
72
|
+
filters: _filters,
|
|
73
|
+
handler: async function (log) {
|
|
74
|
+
const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, undefined, log)
|
|
75
|
+
// let event: Event = <Event>deepCopy(log);
|
|
76
|
+
const event: Event = <Event>log
|
|
77
|
+
const parsed = contractView.rawContract.interface.parseLog(log)
|
|
78
|
+
if (parsed) {
|
|
79
|
+
event.args = parsed.args
|
|
80
|
+
event.decode = (data: BytesLike, topics?: Array<any>) => {
|
|
81
|
+
return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)
|
|
82
|
+
}
|
|
83
|
+
event.event = parsed.name
|
|
84
|
+
event.eventSignature = parsed.signature
|
|
85
|
+
|
|
86
|
+
// TODO fix this bug
|
|
87
|
+
await handler(event, ctx)
|
|
88
|
+
return {
|
|
89
|
+
gauges: ctx.gauges,
|
|
90
|
+
counters: ctx.counters,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
gauges: [],
|
|
95
|
+
counters: [],
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
return this
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public onBlock(handler: (block: Block, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid) {
|
|
103
|
+
const chainId = this.getChainId()
|
|
104
|
+
const contractView = this.CreateBoundContractView()
|
|
105
|
+
|
|
106
|
+
this.blockHandlers.push(async function (block: Block) {
|
|
107
|
+
const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, block, undefined)
|
|
108
|
+
await handler(block, ctx)
|
|
109
|
+
return {
|
|
110
|
+
gauges: ctx.gauges,
|
|
111
|
+
counters: ctx.counters,
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
return this
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public onAllEvents(handler: (event: Log, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid) {
|
|
118
|
+
const _filters: EventFilter[] = []
|
|
119
|
+
const tmpContract = this.CreateBoundContractView()
|
|
120
|
+
|
|
121
|
+
for (const key in tmpContract.filters) {
|
|
122
|
+
_filters.push(tmpContract.filters[key]())
|
|
123
|
+
}
|
|
124
|
+
return this.onEvent(function (log, ctx) {
|
|
125
|
+
return handler(log, ctx)
|
|
126
|
+
}, _filters)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Networkish } from '@ethersproject/networks'
|
|
2
|
+
import Long from 'long'
|
|
3
|
+
import { getNetwork } from '@ethersproject/providers'
|
|
4
|
+
|
|
5
|
+
export class BindOptions {
|
|
6
|
+
address: string
|
|
7
|
+
network?: Networkish = 1
|
|
8
|
+
name?: string
|
|
9
|
+
startBlock?: Long | number
|
|
10
|
+
endBlock?: Long | number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getOptionsSignature(opts: BindOptions): string {
|
|
14
|
+
const sig = [opts.address]
|
|
15
|
+
if (opts.network) {
|
|
16
|
+
sig.push(getNetwork(opts.network).chainId.toString())
|
|
17
|
+
}
|
|
18
|
+
if (opts.name) {
|
|
19
|
+
sig.push(opts.name)
|
|
20
|
+
}
|
|
21
|
+
if (opts.startBlock) {
|
|
22
|
+
sig.push(opts.startBlock.toString())
|
|
23
|
+
}
|
|
24
|
+
if (opts.endBlock) {
|
|
25
|
+
sig.push(opts.endBlock.toString())
|
|
26
|
+
}
|
|
27
|
+
return sig.join('_')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class BindInternalOptions {
|
|
31
|
+
address: string
|
|
32
|
+
network: Networkish
|
|
33
|
+
name: string
|
|
34
|
+
startBlock: Long
|
|
35
|
+
endBlock?: Long
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class SolanaBindOptions extends BindOptions {
|
|
39
|
+
declare network?: string
|
|
40
|
+
processInnerInstruction?: boolean
|
|
41
|
+
}
|
package/src/binds.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BindOptions, getOptionsSignature } from './bind-options'
|
|
2
|
+
import { BaseProcessor } from './base-processor'
|
|
3
|
+
import { Networkish } from '@ethersproject/networks'
|
|
4
|
+
import { getNetwork } from '@ethersproject/providers'
|
|
5
|
+
import { ContractView } from './context'
|
|
6
|
+
import { BaseContract } from 'ethers'
|
|
7
|
+
import { ContractNamer } from './contract-namer'
|
|
8
|
+
|
|
9
|
+
function getKey(abiName: string, address: string, network: Networkish) {
|
|
10
|
+
const chainId = getNetwork(network).chainId.toString()
|
|
11
|
+
return [abiName, address.toLowerCase(), chainId].join('_')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// TODO move to processor state
|
|
15
|
+
const addressToName = new Map<string, string>()
|
|
16
|
+
const namerMap = new Map<string, ContractNamer>()
|
|
17
|
+
|
|
18
|
+
// Get contract name by ABI, and other options
|
|
19
|
+
// If there is contract using same ABI and different (address, network) pair
|
|
20
|
+
// It will be renamed as ABI, ABI_1, ABI_2
|
|
21
|
+
// Otherwise just use same contract name
|
|
22
|
+
export function getContractName(
|
|
23
|
+
abiName: string,
|
|
24
|
+
contractName: string | undefined,
|
|
25
|
+
address: string,
|
|
26
|
+
network: Networkish = 1
|
|
27
|
+
): string {
|
|
28
|
+
const key = getKey(abiName, address, network)
|
|
29
|
+
let name = addressToName.get(key)
|
|
30
|
+
if (name) {
|
|
31
|
+
return name
|
|
32
|
+
}
|
|
33
|
+
if (contractName) {
|
|
34
|
+
addressToName.set(key, contractName)
|
|
35
|
+
return contractName
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let namer = namerMap.get(abiName)
|
|
39
|
+
if (!namer) {
|
|
40
|
+
namer = new ContractNamer(abiName)
|
|
41
|
+
namerMap.set(abiName, namer)
|
|
42
|
+
}
|
|
43
|
+
name = namer.nextName()
|
|
44
|
+
addressToName.set(key, name)
|
|
45
|
+
return name
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getProcessor(abiName: string, opts: BindOptions) {
|
|
49
|
+
const sig = abiName + '_' + getOptionsSignature(opts)
|
|
50
|
+
return global.PROCESSOR_STATE.processorMap.get(sig)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function addProcessor(abiName: string, opts: BindOptions, processor: BaseProcessor<any, any>) {
|
|
54
|
+
const sig = abiName + '_' + getOptionsSignature(opts)
|
|
55
|
+
|
|
56
|
+
global.PROCESSOR_STATE.processors.push(processor)
|
|
57
|
+
global.PROCESSOR_STATE.processorMap.set(sig, processor)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getContractByABI(abiName: string, address: string, network: Networkish) {
|
|
61
|
+
const key = getKey(abiName, address, network)
|
|
62
|
+
return global.PROCESSOR_STATE.contracts.get(key)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function addContractByABI(
|
|
66
|
+
abiName: string,
|
|
67
|
+
address: string,
|
|
68
|
+
network: Networkish,
|
|
69
|
+
contract: ContractView<BaseContract>
|
|
70
|
+
) {
|
|
71
|
+
const key = getKey(abiName, address, network)
|
|
72
|
+
return global.PROCESSOR_STATE.contracts.set(key, contract)
|
|
73
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
import { Log } from "@ethersproject/providers";
|
|
5
|
+
import { getErc20Contract, ApprovalEventObject, TransferEventObject } from ".";
|
|
6
|
+
const mockField = {
|
|
7
|
+
blockHash:
|
|
8
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
9
|
+
blockNumber: 0,
|
|
10
|
+
logIndex: 0,
|
|
11
|
+
removed: false,
|
|
12
|
+
transactionHash:
|
|
13
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
14
|
+
transactionIndex: 0,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function mockApprovalLog(
|
|
18
|
+
contractAddress: string,
|
|
19
|
+
event: ApprovalEventObject
|
|
20
|
+
): Log {
|
|
21
|
+
const contract = getErc20Contract(contractAddress);
|
|
22
|
+
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
|
23
|
+
contract.rawContract.interface.getEvent("Approval"),
|
|
24
|
+
Object.values(event)
|
|
25
|
+
);
|
|
26
|
+
return {
|
|
27
|
+
...mockField,
|
|
28
|
+
address: contractAddress,
|
|
29
|
+
data: encodedLog.data,
|
|
30
|
+
topics: encodedLog.topics,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function mockTransferLog(
|
|
35
|
+
contractAddress: string,
|
|
36
|
+
event: TransferEventObject
|
|
37
|
+
): Log {
|
|
38
|
+
const contract = getErc20Contract(contractAddress);
|
|
39
|
+
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
|
40
|
+
contract.rawContract.interface.getEvent("Transfer"),
|
|
41
|
+
Object.values(event)
|
|
42
|
+
);
|
|
43
|
+
return {
|
|
44
|
+
...mockField,
|
|
45
|
+
address: contractAddress,
|
|
46
|
+
data: encodedLog.data,
|
|
47
|
+
topics: encodedLog.topics,
|
|
48
|
+
};
|
|
49
|
+
}
|