@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,289 @@
1
+ import {
2
+ Contract,
3
+ createImportsForUsedIdentifiers,
4
+ EventDeclaration,
5
+ FunctionDeclaration,
6
+ getFullSignatureAsSymbolForEvent,
7
+ } from 'typechain'
8
+
9
+ import { reservedKeywords } from '@typechain/ethers-v5/dist/codegen/reserved-keywords'
10
+ import { generateInputTypes } from '@typechain/ethers-v5/dist/codegen/types'
11
+ import { getFullSignatureForEvent } from 'typechain/dist/utils/signatures'
12
+
13
+ export function codeGenIndex(contract: Contract): string {
14
+ return `
15
+ export * from '../internal/${contract.name.toLowerCase()}_processor'
16
+ export * from '../internal/${contract.name}'
17
+ `
18
+ }
19
+
20
+ export function codeGenSentioFile(contract: Contract): string {
21
+ const source = `
22
+ const templateContract = ${contract.name}__factory.connect("", DummyProvider)
23
+
24
+ export class ${contract.name}ContractView extends ContractView<${contract.name}> {
25
+ constructor (contract: ${contract.name}) {
26
+ super(contract);
27
+ }
28
+
29
+ ${Object.values(contract.functions)
30
+ .filter((f) => !reservedKeywords.has(f[0].name))
31
+ .flatMap((v) => v.filter((f) => f.stateMutability == 'view').map(generateViewFunction))
32
+ .join('\n')}
33
+ }
34
+
35
+ export class ${contract.name}BoundContractView extends BoundContractView<${contract.name}, ${
36
+ contract.name
37
+ }ContractView> {
38
+ // constructor (contract: ${contract.name}) {
39
+ // super(contract);
40
+ // }
41
+
42
+ ${Object.values(contract.functions)
43
+ .filter((f) => !reservedKeywords.has(f[0].name))
44
+ .flatMap((v) => v.filter((f) => f.stateMutability == 'view').map(generateBoundViewFunction))
45
+ .join('\n')}
46
+ }
47
+
48
+ export type ${contract.name}Context = Context<${contract.name}, ${contract.name}BoundContractView>
49
+
50
+ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${contract.name}, ${
51
+ contract.name
52
+ }BoundContractView> {
53
+ bindInternal(options: BindOptions) {
54
+ let processor = getProcessor("${contract.name}", options) as ${contract.name}Processor
55
+ if (!processor) {
56
+ const finalOptions = Object.assign({}, options)
57
+ finalOptions.name = getContractName("${contract.name}", options.name, options.address, options.network)
58
+ processor = new ${contract.name}Processor(finalOptions)
59
+ addProcessor("${contract.name}", options, processor)
60
+ }
61
+ return processor
62
+ }
63
+
64
+ ${Object.values(contract.events)
65
+ .map((events) => {
66
+ if (events.length === 1) {
67
+ return generateOnEventFunction(events[0], contract.name, false)
68
+ } else {
69
+ return events.map((e) => generateOnEventFunction(e, contract.name, true)).join('\n')
70
+ }
71
+ })
72
+ .join('\n')}
73
+ }
74
+
75
+ export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {
76
+ ${Object.values(contract.events)
77
+ .map((events) => {
78
+ if (events.length === 1) {
79
+ return generateOnEventFunction(events[0], contract.name, false)
80
+ } else {
81
+ return events.map((e) => generateOnEventFunction(e, contract.name, true)).join('\n')
82
+ }
83
+ })
84
+ .join('\n')}
85
+
86
+ public static filters = templateContract.filters
87
+
88
+ protected CreateBoundContractView(): ${contract.name}BoundContractView {
89
+ const view = get${contract.name}Contract(this.config.address, this.config.network)
90
+ return new ${contract.name}BoundContractView(view)
91
+ }
92
+
93
+ public static bind(options: BindOptions): ${contract.name}Processor {
94
+ let processor = getProcessor("${contract.name}", options) as ${contract.name}Processor
95
+ if (!processor) {
96
+ // const wrapper = get${contract.name}Contract(options.address, options.network)
97
+
98
+ const finalOptions = Object.assign({}, options)
99
+ finalOptions.name = getContractName("${contract.name}", options.name, options.address, options.network)
100
+ processor = new ${contract.name}Processor(finalOptions)
101
+ addProcessor("${contract.name}", options, processor)
102
+ }
103
+ return processor
104
+ }
105
+ }
106
+
107
+ export function get${contract.name}Contract(address: string, network: Networkish = 1): ${contract.name}ContractView {
108
+ let contract = getContractByABI("${contract.name}", address, network) as ${contract.name}ContractView
109
+ if (!contract) {
110
+ const rawContract = ${contract.name}__factory.connect(address, getProvider(network))
111
+ contract = new ${contract.name}ContractView(rawContract)
112
+ addContractByABI("${contract.name}", address, network, contract)
113
+ }
114
+ return contract
115
+ }
116
+ `
117
+
118
+ const imports = createImportsForUsedIdentifiers(
119
+ {
120
+ ethers: ['BigNumber', 'BigNumberish', 'CallOverrides', 'BytesLike'],
121
+ '@ethersproject/providers': ['Networkish'],
122
+ '@sentio/sdk': [
123
+ 'addContractByABI',
124
+ 'getContractByABI',
125
+ 'addProcessor',
126
+ 'getProcessor',
127
+ 'getProvider',
128
+ 'transformEtherError',
129
+ 'BindOptions',
130
+ 'BaseProcessor',
131
+ 'BaseProcessorTemplate',
132
+ 'BoundContractView',
133
+ 'Context',
134
+ 'ContractView',
135
+ 'DummyProvider',
136
+ 'getContractName',
137
+ ],
138
+ './common': ['PromiseOrValue'],
139
+ './index': [`${contract.name}`, `${contract.name}__factory`],
140
+ [`./${contract.name}`]: (<string[]>[]).concat(
141
+ ...Object.values(contract.events).map((events) => {
142
+ if (events.length === 1) {
143
+ return [`${events[0].name}Event`, `${events[0].name}EventFilter`]
144
+ } else {
145
+ return events.flatMap((e) => [
146
+ `${getFullSignatureAsSymbolForEvent(e)}_Event`,
147
+ `${getFullSignatureAsSymbolForEvent(e)}_EventFilter`,
148
+ ])
149
+ }
150
+ })
151
+ ),
152
+ },
153
+ source
154
+ )
155
+
156
+ return imports + source
157
+ }
158
+
159
+ export function codeGenTestUtilsFile(contract: Contract): string {
160
+ const source = `
161
+ const mockField = {
162
+ blockHash:
163
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
164
+ blockNumber: 0,
165
+ logIndex: 0,
166
+ removed: false,
167
+ transactionHash:
168
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
169
+ transactionIndex: 0,
170
+ }
171
+ ${Object.values(contract.events)
172
+ .map((events) => {
173
+ if (events.length === 1) {
174
+ return generateMockEventLogFunction(events[0], contract.name, false)
175
+ } else {
176
+ return events.map((e) => generateMockEventLogFunction(e, contract.name, true)).join('\n')
177
+ }
178
+ })
179
+ .join('\n')}
180
+ `
181
+
182
+ const imports = createImportsForUsedIdentifiers(
183
+ {
184
+ '@ethersproject/providers': ['Log'],
185
+ '.': [
186
+ `get${contract.name}Contract`,
187
+ ...Object.values(contract.events).flatMap((events) => {
188
+ if (events.length === 1) {
189
+ return `${events[0].name}EventObject`
190
+ } else {
191
+ return events.flatMap((e) => `${getFullSignatureAsSymbolForEvent(e)}_EventObject`)
192
+ }
193
+ }),
194
+ ],
195
+ },
196
+ source
197
+ )
198
+
199
+ return imports + source
200
+ }
201
+
202
+ function generateOnEventFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {
203
+ let eventName = event.name
204
+ if (includeArgTypes) {
205
+ eventName = getFullSignatureAsSymbolForEvent(event) + '_'
206
+ }
207
+
208
+ const filterName = getFullSignatureForEvent(event)
209
+
210
+ return `
211
+ on${eventName}(
212
+ handler: (event: ${eventName}Event, ctx: ${contractName}Context) => void,
213
+ filter?: ${eventName}EventFilter | ${eventName}EventFilter[]
214
+ ) {
215
+ if (!filter) {
216
+ filter = ${contractName}Processor.filters['${filterName}'](${event.inputs.map(() => 'null').join(',')})
217
+ }
218
+ return super.onEvent(handler, filter)
219
+ }
220
+ `
221
+ }
222
+
223
+ function generateViewFunction(func: FunctionDeclaration): string {
224
+ return `
225
+ async ${func.name}(${generateInputTypes(func.inputs, { useStructs: true })}overrides?: CallOverrides) {
226
+ try {
227
+ if (overrides) {
228
+ return await this.contract.${func.name}(${
229
+ func.inputs.length > 0 ? func.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
230
+ } overrides)
231
+ } else {
232
+ return await this.contract.${func.name}(${func.inputs
233
+ .map((input, index) => input.name || `arg${index}`)
234
+ .join(',')})
235
+ }
236
+ } catch (e) {
237
+ throw transformEtherError(e, undefined)
238
+ }
239
+ }
240
+ `
241
+ }
242
+
243
+ function generateBoundViewFunction(func: FunctionDeclaration): string {
244
+ return `
245
+ async ${func.name}(${generateInputTypes(func.inputs, { useStructs: true })}overrides?: CallOverrides) {
246
+ try {
247
+ if (!overrides && this.context) {
248
+ overrides = {
249
+ blockTag: this.context.blockNumber.toNumber(),
250
+ }
251
+ }
252
+ if (overrides) {
253
+ return await this.view.${func.name}(${
254
+ func.inputs.length > 0 ? func.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
255
+ } overrides)
256
+ } else {
257
+ return await this.view.${func.name}(${func.inputs.map((input, index) => input.name || `arg${index}`).join(',')})
258
+ }
259
+ } catch (e) {
260
+ throw transformEtherError(e, this.context)
261
+ }
262
+ }
263
+ `
264
+ }
265
+
266
+ function generateMockEventLogFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {
267
+ let eventName = event.name
268
+ let eventNameWithSignature = event.name
269
+ if (includeArgTypes) {
270
+ eventName = getFullSignatureAsSymbolForEvent(event) + '_'
271
+ eventNameWithSignature = getFullSignatureForEvent(event)
272
+ }
273
+
274
+ return `
275
+ export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): Log {
276
+ const contract = get${contractName}Contract(contractAddress)
277
+ const encodedLog = contract.rawContract.interface.encodeEventLog(
278
+ contract.rawContract.interface.getEvent('${eventNameWithSignature}'),
279
+ Object.values(event)
280
+ )
281
+ return {
282
+ ...mockField,
283
+ address: contractAddress,
284
+ data: encodedLog.data,
285
+ topics: encodedLog.topics,
286
+ }
287
+ }
288
+ `
289
+ }
@@ -0,0 +1,50 @@
1
+ import Ethers from '@typechain/ethers-v5'
2
+ import { Config, extractAbi, extractDocumentation, FileDescription, parse, shortenFullJsonFilePath } from 'typechain'
3
+ import { dirname, join, relative } from 'path'
4
+ import { codeGenIndex, codeGenSentioFile, codeGenTestUtilsFile } from './codegen'
5
+
6
+ export default class EthersSentio extends Ethers {
7
+ constructor(config: Config) {
8
+ if (!config.outDir) {
9
+ throw new Error('Out put path not specificed')
10
+ }
11
+ super(config)
12
+ }
13
+
14
+ // TODO(pc): also have to override transformBinFile, transformFile
15
+ override transformAbiOrFullJsonFile(file: FileDescription): FileDescription[] | void {
16
+ const abi = extractAbi(file.contents)
17
+ if (abi.length === 0) {
18
+ return
19
+ }
20
+
21
+ const documentation = extractDocumentation(file.contents)
22
+
23
+ const jsonPath = relative(this.cfg.inputDir, shortenFullJsonFilePath(file.path, this.cfg.allFiles))
24
+ const contract = parse(abi, jsonPath, documentation)
25
+ const files = super.transformAbiOrFullJsonFile(file)
26
+
27
+ if (files !== undefined) {
28
+ // files.forEach(this.transformFilePath)
29
+ // for (const file of files) {
30
+ // this.transformFilePath(file)
31
+ // }
32
+
33
+ return [
34
+ ...files,
35
+ {
36
+ path: join(dirname(files[0].path), `${contract.name.toLowerCase()}_processor.ts`),
37
+ contents: codeGenSentioFile(contract),
38
+ },
39
+ {
40
+ path: join(dirname(files[0].path), '..', contract.name.toLowerCase(), 'index.ts'),
41
+ contents: codeGenIndex(contract),
42
+ },
43
+ {
44
+ path: join(dirname(files[0].path), '..', contract.name.toLowerCase(), 'test-utils.ts'),
45
+ contents: codeGenTestUtilsFile(contract),
46
+ },
47
+ ]
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "..",
5
+ "outDir": "../../lib"
6
+ },
7
+ "exclude": ["lib"],
8
+ "include": ["."]
9
+ }