@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.
Files changed (299) hide show
  1. package/{base-processor-template.d.ts → lib/base-processor-template.d.ts} +0 -0
  2. package/{base-processor-template.js → lib/base-processor-template.js} +0 -0
  3. package/lib/base-processor-template.js.map +1 -0
  4. package/{base-processor.d.ts → lib/base-processor.d.ts} +0 -0
  5. package/{base-processor.js → lib/base-processor.js} +0 -0
  6. package/lib/base-processor.js.map +1 -0
  7. package/{bind-options.d.ts → lib/bind-options.d.ts} +0 -0
  8. package/{bind-options.js → lib/bind-options.js} +0 -0
  9. package/lib/bind-options.js.map +1 -0
  10. package/{binds.d.ts → lib/binds.d.ts} +0 -0
  11. package/{binds.js → lib/binds.js} +0 -0
  12. package/lib/binds.js.map +1 -0
  13. package/{builtin → lib/builtin}/erc20/index.d.ts +0 -0
  14. package/{builtin → lib/builtin}/erc20/index.js +0 -0
  15. package/lib/builtin/erc20/index.js.map +1 -0
  16. package/{builtin → lib/builtin}/erc20/test-utils.d.ts +0 -0
  17. package/{builtin → lib/builtin}/erc20/test-utils.js +0 -0
  18. package/lib/builtin/erc20/test-utils.js.map +1 -0
  19. package/{builtin → lib/builtin}/internal/Erc20.d.ts +0 -0
  20. package/{builtin → lib/builtin}/internal/Erc20.js +0 -0
  21. package/lib/builtin/internal/Erc20.js.map +1 -0
  22. package/{builtin → lib/builtin}/internal/common.d.ts +0 -0
  23. package/{builtin → lib/builtin}/internal/common.js +0 -0
  24. package/lib/builtin/internal/common.js.map +1 -0
  25. package/{builtin → lib/builtin}/internal/erc20_processor.d.ts +0 -0
  26. package/{builtin → lib/builtin}/internal/erc20_processor.js +0 -0
  27. package/lib/builtin/internal/erc20_processor.js.map +1 -0
  28. package/{builtin → lib/builtin}/internal/factories/Erc20__factory.d.ts +0 -0
  29. package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js +0 -0
  30. package/lib/builtin/internal/factories/Erc20__factory.js.map +1 -0
  31. package/{builtin → lib/builtin}/internal/factories/index.d.ts +0 -0
  32. package/{builtin → lib/builtin}/internal/factories/index.js +0 -0
  33. package/{builtin → lib/builtin}/internal/factories/index.js.map +1 -1
  34. package/{builtin → lib/builtin}/internal/index.d.ts +0 -0
  35. package/{builtin → lib/builtin}/internal/index.js +0 -0
  36. package/lib/builtin/internal/index.js.map +1 -0
  37. package/{chain-config.d.ts → lib/chain-config.d.ts} +0 -0
  38. package/{chain-config.js → lib/chain-config.js} +0 -0
  39. package/lib/chain-config.js.map +1 -0
  40. package/{cli → lib/cli}/build.d.ts +0 -0
  41. package/{cli → lib/cli}/build.js +0 -0
  42. package/lib/cli/build.js.map +1 -0
  43. package/{cli → lib/cli}/cli.d.ts +0 -0
  44. package/{cli → lib/cli}/cli.js +0 -0
  45. package/lib/cli/cli.js.map +1 -0
  46. package/{cli → lib/cli}/config.d.ts +0 -0
  47. package/{cli → lib/cli}/config.js +0 -0
  48. package/lib/cli/config.js.map +1 -0
  49. package/{cli → lib/cli}/key.d.ts +0 -0
  50. package/{cli → lib/cli}/key.js +0 -0
  51. package/{cli → lib/cli}/key.js.map +1 -1
  52. package/{cli → lib/cli}/solana-code-gen.d.ts +0 -0
  53. package/{cli → lib/cli}/solana-code-gen.js +0 -0
  54. package/{cli → lib/cli}/solana-code-gen.js.map +1 -1
  55. package/{cli → lib/cli}/upload.d.ts +0 -0
  56. package/{cli → lib/cli}/upload.js +0 -0
  57. package/{cli → lib/cli}/upload.js.map +1 -1
  58. package/{cli → lib/cli}/webpack.config.js +0 -0
  59. package/{context.d.ts → lib/context.d.ts} +0 -0
  60. package/{context.js → lib/context.js} +0 -0
  61. package/lib/context.js.map +1 -0
  62. package/{contract-namer.d.ts → lib/contract-namer.d.ts} +0 -0
  63. package/{contract-namer.js → lib/contract-namer.js} +0 -0
  64. package/{contract-namer.js.map → lib/contract-namer.js.map} +1 -1
  65. package/{error.d.ts → lib/error.d.ts} +0 -0
  66. package/{error.js → lib/error.js} +0 -0
  67. package/lib/error.js.map +1 -0
  68. package/{gen → lib/gen}/builtin.d.ts +0 -0
  69. package/{gen → lib/gen}/builtin.js +0 -0
  70. package/lib/gen/builtin.js.map +1 -0
  71. package/{gen → lib/gen}/google/protobuf/empty.d.ts +0 -0
  72. package/{gen → lib/gen}/google/protobuf/empty.js +0 -0
  73. package/lib/gen/google/protobuf/empty.js.map +1 -0
  74. package/{gen → lib/gen}/processor/protos/processor.d.ts +0 -0
  75. package/{gen → lib/gen}/processor/protos/processor.js +0 -0
  76. package/lib/gen/processor/protos/processor.js.map +1 -0
  77. package/{generic-processor.d.ts → lib/generic-processor.d.ts} +0 -0
  78. package/{generic-processor.js → lib/generic-processor.js} +0 -0
  79. package/lib/generic-processor.js.map +1 -0
  80. package/{index.d.ts → lib/index.d.ts} +0 -0
  81. package/{index.js → lib/index.js} +0 -0
  82. package/lib/index.js.map +1 -0
  83. package/lib/loader.d.ts +5 -0
  84. package/lib/loader.js +30 -0
  85. package/lib/loader.js.map +1 -0
  86. package/{meter.d.ts → lib/meter.d.ts} +0 -0
  87. package/{meter.js → lib/meter.js} +0 -0
  88. package/lib/meter.js.map +1 -0
  89. package/{numberish.d.ts → lib/numberish.d.ts} +0 -0
  90. package/{numberish.js → lib/numberish.js} +0 -0
  91. package/lib/numberish.js.map +1 -0
  92. package/{numberish.test.d.ts → lib/numberish.test.d.ts} +0 -0
  93. package/{numberish.test.js → lib/numberish.test.js} +0 -0
  94. package/{numberish.test.js.map → lib/numberish.test.js.map} +1 -1
  95. package/{processor-runner.d.ts → lib/processor-runner.d.ts} +0 -0
  96. package/{processor-runner.js → lib/processor-runner.js} +2 -27
  97. package/lib/processor-runner.js.map +1 -0
  98. package/{processor-state.d.ts → lib/processor-state.d.ts} +0 -0
  99. package/{processor-state.js → lib/processor-state.js} +0 -0
  100. package/lib/processor-state.js.map +1 -0
  101. package/{promise-or-void.d.ts → lib/promise-or-void.d.ts} +0 -0
  102. package/{promise-or-void.js → lib/promise-or-void.js} +0 -0
  103. package/lib/promise-or-void.js.map +1 -0
  104. package/{provider.d.ts → lib/provider.d.ts} +0 -0
  105. package/{provider.js → lib/provider.js} +0 -0
  106. package/lib/provider.js.map +1 -0
  107. package/{release.config.js → lib/release.config.js} +0 -0
  108. package/{service.d.ts → lib/service.d.ts} +2 -1
  109. package/{service.js → lib/service.js} +6 -3
  110. package/lib/service.js.map +1 -0
  111. package/{solana → lib/solana}/builtin/index.d.ts +0 -0
  112. package/{solana → lib/solana}/builtin/index.js +0 -0
  113. package/lib/solana/builtin/index.js.map +1 -0
  114. package/{solana → lib/solana}/builtin/spl-token-processor.d.ts +0 -0
  115. package/{solana → lib/solana}/builtin/spl-token-processor.js +0 -0
  116. package/lib/solana/builtin/spl-token-processor.js.map +1 -0
  117. package/{solana → lib/solana}/builtin/types.d.ts +0 -0
  118. package/{solana → lib/solana}/builtin/types.js +0 -0
  119. package/lib/solana/builtin/types.js.map +1 -0
  120. package/{solana → lib/solana}/builtin/wormhole-processor.d.ts +0 -0
  121. package/{solana → lib/solana}/builtin/wormhole-processor.js +0 -0
  122. package/lib/solana/builtin/wormhole-processor.js.map +1 -0
  123. package/{solana-processor.d.ts → lib/solana-processor.d.ts} +0 -0
  124. package/{solana-processor.js → lib/solana-processor.js} +0 -0
  125. package/lib/solana-processor.js.map +1 -0
  126. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.d.ts +0 -0
  127. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js +0 -0
  128. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js.map +0 -0
  129. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.d.ts +0 -0
  130. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js +0 -0
  131. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js.map +0 -0
  132. package/{test → lib/test}/codegen.test.d.ts +0 -0
  133. package/{test → lib/test}/codegen.test.js +1 -1
  134. package/lib/test/codegen.test.js.map +1 -0
  135. package/{test → lib/test}/erc20-template.d.ts +0 -0
  136. package/{test → lib/test}/erc20-template.js +0 -0
  137. package/lib/test/erc20-template.js.map +1 -0
  138. package/{test → lib/test}/erc20-template.test.d.ts +0 -0
  139. package/{test → lib/test}/erc20-template.test.js +1 -3
  140. package/lib/test/erc20-template.test.js.map +1 -0
  141. package/{test → lib/test}/erc20.d.ts +0 -0
  142. package/{test → lib/test}/erc20.js +0 -0
  143. package/lib/test/erc20.js.map +1 -0
  144. package/{test → lib/test}/erc20.test.d.ts +0 -0
  145. package/{test → lib/test}/erc20.test.js +1 -3
  146. package/lib/test/erc20.test.js.map +1 -0
  147. package/{test → lib/test}/generic-processor.test.d.ts +0 -0
  148. package/{test → lib/test}/generic-processor.test.js +14 -4
  149. package/lib/test/generic-processor.test.js.map +1 -0
  150. package/{test → lib/test}/index.d.ts +0 -0
  151. package/{test → lib/test}/index.js +0 -0
  152. package/{test → lib/test}/index.js.map +1 -1
  153. package/{test → lib/test}/metric-utils.d.ts +0 -0
  154. package/{test → lib/test}/metric-utils.js +0 -0
  155. package/lib/test/metric-utils.js.map +1 -0
  156. package/{test → lib/test}/mirrorworld.d.ts +0 -0
  157. package/{test → lib/test}/mirrorworld.js +0 -0
  158. package/{test → lib/test}/mirrorworld.js.map +1 -1
  159. package/{test → lib/test}/solana.test.d.ts +0 -0
  160. package/{test → lib/test}/solana.test.js +3 -3
  161. package/lib/test/solana.test.js.map +1 -0
  162. package/{test → lib/test}/test-processor-server.d.ts +1 -1
  163. package/{test → lib/test}/test-processor-server.js +3 -8
  164. package/lib/test/test-processor-server.js.map +1 -0
  165. package/{test → lib/test}/types/game_wallet.d.ts +0 -0
  166. package/{test → lib/test}/types/game_wallet.js +0 -0
  167. package/lib/test/types/game_wallet.js.map +1 -0
  168. package/{test → lib/test}/types/game_wallet_processor.d.ts +0 -0
  169. package/{test → lib/test}/types/game_wallet_processor.js +0 -0
  170. package/lib/test/types/game_wallet_processor.js.map +1 -0
  171. package/{test → lib/test}/wormhole-token-bridge.d.ts +0 -0
  172. package/{test → lib/test}/wormhole-token-bridge.js +0 -0
  173. package/lib/test/wormhole-token-bridge.js.map +1 -0
  174. package/{utils → lib/utils}/chainmap.d.ts +0 -0
  175. package/{utils → lib/utils}/chainmap.js +0 -0
  176. package/lib/utils/chainmap.js.map +1 -0
  177. package/{utils → lib/utils}/convert.d.ts +0 -0
  178. package/{utils → lib/utils}/convert.js +0 -0
  179. package/lib/utils/convert.js.map +1 -0
  180. package/{utils → lib/utils}/index.d.ts +0 -0
  181. package/{utils → lib/utils}/index.js +0 -0
  182. package/lib/utils/index.js.map +1 -0
  183. package/package.json +47 -6
  184. package/src/abis/erc20.json +198 -0
  185. package/src/base-processor-template.ts +92 -0
  186. package/src/base-processor.ts +128 -0
  187. package/src/bind-options.ts +41 -0
  188. package/src/binds.ts +73 -0
  189. package/src/builtin/erc20/index.ts +6 -0
  190. package/src/builtin/erc20/test-utils.ts +49 -0
  191. package/src/builtin/internal/Erc20.ts +356 -0
  192. package/src/builtin/internal/common.ts +46 -0
  193. package/src/builtin/internal/erc20_processor.ts +295 -0
  194. package/src/builtin/internal/factories/Erc20__factory.ts +216 -0
  195. package/src/builtin/internal/factories/index.ts +4 -0
  196. package/src/builtin/internal/index.ts +6 -0
  197. package/src/chain-config.ts +6 -0
  198. package/src/cli/build.ts +180 -0
  199. package/src/cli/cli.ts +217 -0
  200. package/src/cli/config.ts +43 -0
  201. package/src/cli/key.ts +43 -0
  202. package/src/cli/solana-code-gen.ts +16 -0
  203. package/src/cli/upload.ts +86 -0
  204. package/src/cli/webpack.config.js +42 -0
  205. package/src/context.ts +93 -0
  206. package/src/contract-namer.ts +17 -0
  207. package/src/error.ts +43 -0
  208. package/src/gen/builtin.ts +22 -0
  209. package/src/gen/google/protobuf/empty.ts +70 -0
  210. package/src/gen/processor/protos/processor.ts +3071 -0
  211. package/src/generic-processor.ts +38 -0
  212. package/src/index.ts +19 -0
  213. package/src/loader.ts +24 -0
  214. package/src/meter.ts +122 -0
  215. package/src/numberish.test.ts +82 -0
  216. package/src/numberish.ts +99 -0
  217. package/src/processor-runner.ts +49 -0
  218. package/src/processor-state.ts +24 -0
  219. package/src/promise-or-void.ts +1 -0
  220. package/src/provider.ts +74 -0
  221. package/src/service.ts +439 -0
  222. package/src/solana/builtin/index.ts +2 -0
  223. package/src/solana/builtin/spl-token-processor.ts +164 -0
  224. package/src/solana/builtin/types.ts +268 -0
  225. package/src/solana/builtin/wormhole-processor.ts +178 -0
  226. package/src/solana-processor.ts +105 -0
  227. package/src/target-ethers-sentio/codegen.ts +289 -0
  228. package/src/target-ethers-sentio/index.ts +50 -0
  229. package/src/target-ethers-sentio/tsconfig.json +9 -0
  230. package/src/test/abis/evm/anyswapRouter.json +490 -0
  231. package/src/test/abis/solana/mirrorworld.json +1392 -0
  232. package/src/test/codegen.test.ts +26 -0
  233. package/src/test/erc20-template.test.ts +37 -0
  234. package/src/test/erc20-template.ts +25 -0
  235. package/src/test/erc20.test.ts +90 -0
  236. package/src/test/erc20.ts +48 -0
  237. package/src/test/generic-processor.test.ts +70 -0
  238. package/src/test/index.ts +1 -0
  239. package/src/test/metric-utils.ts +49 -0
  240. package/src/test/mirrorworld.ts +40 -0
  241. package/src/test/sentio.yaml +4 -0
  242. package/src/test/solana.test.ts +93 -0
  243. package/src/test/test-processor-server.ts +205 -0
  244. package/src/test/types/game_wallet.ts +1392 -0
  245. package/src/test/types/game_wallet_processor.ts +113 -0
  246. package/src/test/wormhole-token-bridge.ts +21 -0
  247. package/src/types/global.d.ts +17 -0
  248. package/src/utils/chainmap.ts +95 -0
  249. package/src/utils/convert.ts +6 -0
  250. package/src/utils/index.ts +2 -0
  251. package/base-processor-template.js.map +0 -1
  252. package/base-processor.js.map +0 -1
  253. package/bind-options.js.map +0 -1
  254. package/binds.js.map +0 -1
  255. package/builtin/erc20/index.js.map +0 -1
  256. package/builtin/erc20/test-utils.js.map +0 -1
  257. package/builtin/internal/Erc20.js.map +0 -1
  258. package/builtin/internal/common.js.map +0 -1
  259. package/builtin/internal/erc20_processor.js.map +0 -1
  260. package/builtin/internal/factories/Erc20__factory.js.map +0 -1
  261. package/builtin/internal/index.js.map +0 -1
  262. package/chain-config.js.map +0 -1
  263. package/cli/build.js.map +0 -1
  264. package/cli/cli.js.map +0 -1
  265. package/cli/config.js.map +0 -1
  266. package/context.js.map +0 -1
  267. package/error.js.map +0 -1
  268. package/gen/builtin.js.map +0 -1
  269. package/gen/google/protobuf/empty.js.map +0 -1
  270. package/gen/processor/protos/processor.js.map +0 -1
  271. package/generic-processor.js.map +0 -1
  272. package/index.js.map +0 -1
  273. package/meter.js.map +0 -1
  274. package/numberish.js.map +0 -1
  275. package/processor-runner.js.map +0 -1
  276. package/processor-state.js.map +0 -1
  277. package/promise-or-void.js.map +0 -1
  278. package/provider.js.map +0 -1
  279. package/service.js.map +0 -1
  280. package/solana/builtin/index.js.map +0 -1
  281. package/solana/builtin/spl-token-processor.js.map +0 -1
  282. package/solana/builtin/types.js.map +0 -1
  283. package/solana/builtin/wormhole-processor.js.map +0 -1
  284. package/solana-processor.js.map +0 -1
  285. package/test/codegen.test.js.map +0 -1
  286. package/test/erc20-template.js.map +0 -1
  287. package/test/erc20-template.test.js.map +0 -1
  288. package/test/erc20.js.map +0 -1
  289. package/test/erc20.test.js.map +0 -1
  290. package/test/generic-processor.test.js.map +0 -1
  291. package/test/metric-utils.js.map +0 -1
  292. package/test/solana.test.js.map +0 -1
  293. package/test/test-processor-server.js.map +0 -1
  294. package/test/types/game_wallet.js.map +0 -1
  295. package/test/types/game_wallet_processor.js.map +0 -1
  296. package/test/wormhole-token-bridge.js.map +0 -1
  297. package/utils/chainmap.js.map +0 -1
  298. package/utils/convert.js.map +0 -1
  299. 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,6 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+
5
+ export * from "../internal/erc20_processor";
6
+ export * from "../internal/Erc20";
@@ -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
+ }