@sentio/sdk 1.40.5-rc.6 → 1.41.0-rc.1

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 (240) hide show
  1. package/lib/builtin/eacaggregatorproxy/index.js +3 -16
  2. package/lib/builtin/eacaggregatorproxy/index.js.map +1 -1
  3. package/lib/builtin/eacaggregatorproxy/test-utils.d.ts +5 -5
  4. package/lib/builtin/eacaggregatorproxy/test-utils.js +8 -4
  5. package/lib/builtin/eacaggregatorproxy/test-utils.js.map +1 -1
  6. package/lib/builtin/erc1155/index.js +3 -16
  7. package/lib/builtin/erc1155/index.js.map +1 -1
  8. package/lib/builtin/erc1155/test-utils.d.ts +5 -5
  9. package/lib/builtin/erc1155/test-utils.js +8 -4
  10. package/lib/builtin/erc1155/test-utils.js.map +1 -1
  11. package/lib/builtin/erc20/index.js +3 -16
  12. package/lib/builtin/erc20/index.js.map +1 -1
  13. package/lib/builtin/erc20/test-utils.d.ts +4 -4
  14. package/lib/builtin/erc20/test-utils.js +6 -3
  15. package/lib/builtin/erc20/test-utils.js.map +1 -1
  16. package/lib/builtin/erc20bytes/index.js +3 -16
  17. package/lib/builtin/erc20bytes/index.js.map +1 -1
  18. package/lib/builtin/erc20bytes/test-utils.d.ts +3 -3
  19. package/lib/builtin/erc20bytes/test-utils.js +4 -2
  20. package/lib/builtin/erc20bytes/test-utils.js.map +1 -1
  21. package/lib/builtin/erc721/index.js +3 -16
  22. package/lib/builtin/erc721/index.js.map +1 -1
  23. package/lib/builtin/erc721/test-utils.d.ts +4 -4
  24. package/lib/builtin/erc721/test-utils.js +6 -3
  25. package/lib/builtin/erc721/test-utils.js.map +1 -1
  26. package/lib/builtin/index.js +5 -27
  27. package/lib/builtin/index.js.map +1 -1
  28. package/lib/builtin/internal/EACAggregatorProxy.d.ts +19 -430
  29. package/lib/builtin/internal/EACAggregatorProxy.js.map +1 -1
  30. package/lib/builtin/internal/ERC1155.d.ts +18 -161
  31. package/lib/builtin/internal/ERC1155.js.map +1 -1
  32. package/lib/builtin/internal/ERC20.d.ts +12 -279
  33. package/lib/builtin/internal/ERC20.js.map +1 -1
  34. package/lib/builtin/internal/ERC20Bytes.d.ts +11 -146
  35. package/lib/builtin/internal/ERC20Bytes.js.map +1 -1
  36. package/lib/builtin/internal/ERC721.d.ts +12 -222
  37. package/lib/builtin/internal/ERC721.js.map +1 -1
  38. package/lib/builtin/internal/WETH9.d.ts +16 -191
  39. package/lib/builtin/internal/WETH9.js.map +1 -1
  40. package/lib/builtin/internal/common.d.ts +3 -18
  41. package/lib/builtin/internal/common.js +6 -0
  42. package/lib/builtin/internal/common.js.map +1 -1
  43. package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +161 -168
  44. package/lib/builtin/internal/eacaggregatorproxy_processor.js +94 -288
  45. package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
  46. package/lib/builtin/internal/erc1155_processor.d.ts +45 -50
  47. package/lib/builtin/internal/erc1155_processor.js +68 -132
  48. package/lib/builtin/internal/erc1155_processor.js.map +1 -1
  49. package/lib/builtin/internal/erc20_processor.d.ts +59 -63
  50. package/lib/builtin/internal/erc20_processor.js +64 -155
  51. package/lib/builtin/internal/erc20_processor.js.map +1 -1
  52. package/lib/builtin/internal/erc20bytes_processor.d.ts +37 -40
  53. package/lib/builtin/internal/erc20bytes_processor.js +50 -118
  54. package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
  55. package/lib/builtin/internal/erc721_processor.d.ts +56 -60
  56. package/lib/builtin/internal/erc721_processor.js +66 -167
  57. package/lib/builtin/internal/erc721_processor.js.map +1 -1
  58. package/lib/builtin/internal/factories/EACAggregatorProxy__factory.d.ts +1 -2
  59. package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js +1 -1
  60. package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js.map +1 -1
  61. package/lib/builtin/internal/factories/ERC1155__factory.d.ts +1 -2
  62. package/lib/builtin/internal/factories/ERC1155__factory.js +1 -1
  63. package/lib/builtin/internal/factories/ERC1155__factory.js.map +1 -1
  64. package/lib/builtin/internal/factories/ERC20Bytes__factory.d.ts +1 -2
  65. package/lib/builtin/internal/factories/ERC20Bytes__factory.js +1 -1
  66. package/lib/builtin/internal/factories/ERC20Bytes__factory.js.map +1 -1
  67. package/lib/builtin/internal/factories/ERC20__factory.d.ts +1 -2
  68. package/lib/builtin/internal/factories/ERC20__factory.js +1 -1
  69. package/lib/builtin/internal/factories/ERC20__factory.js.map +1 -1
  70. package/lib/builtin/internal/factories/ERC721__factory.d.ts +1 -2
  71. package/lib/builtin/internal/factories/ERC721__factory.js +1 -1
  72. package/lib/builtin/internal/factories/ERC721__factory.js.map +1 -1
  73. package/lib/builtin/internal/factories/WETH9__factory.d.ts +1 -2
  74. package/lib/builtin/internal/factories/WETH9__factory.js +1 -1
  75. package/lib/builtin/internal/factories/WETH9__factory.js.map +1 -1
  76. package/lib/builtin/internal/index.js +2 -24
  77. package/lib/builtin/internal/index.js.map +1 -1
  78. package/lib/builtin/internal/weth9_processor.d.ts +44 -49
  79. package/lib/builtin/internal/weth9_processor.js +70 -144
  80. package/lib/builtin/internal/weth9_processor.js.map +1 -1
  81. package/lib/builtin/weth9/index.js +3 -16
  82. package/lib/builtin/weth9/index.js.map +1 -1
  83. package/lib/builtin/weth9/test-utils.d.ts +5 -5
  84. package/lib/builtin/weth9/test-utils.js +8 -4
  85. package/lib/builtin/weth9/test-utils.js.map +1 -1
  86. package/lib/core/big-decimal.d.ts +6 -0
  87. package/lib/core/big-decimal.js +6 -2
  88. package/lib/core/big-decimal.js.map +1 -1
  89. package/lib/core/bind-options.d.ts +1 -1
  90. package/lib/core/bind-options.js +2 -2
  91. package/lib/core/bind-options.js.map +1 -1
  92. package/lib/core/context.d.ts +8 -14
  93. package/lib/core/context.js +7 -6
  94. package/lib/core/context.js.map +1 -1
  95. package/lib/core/core-plugin.d.ts +1 -1
  96. package/lib/core/core-plugin.js +1 -1
  97. package/lib/core/core-plugin.js.map +1 -1
  98. package/lib/core/generic-processor.test.js.map +1 -1
  99. package/lib/core/index.d.ts +0 -5
  100. package/lib/core/index.js +1 -9
  101. package/lib/core/index.js.map +1 -1
  102. package/lib/core/numberish.d.ts +2 -3
  103. package/lib/core/numberish.js +35 -33
  104. package/lib/core/numberish.js.map +1 -1
  105. package/lib/core/numberish.test.js.map +1 -1
  106. package/lib/core/sui-plugin.d.ts +1 -1
  107. package/lib/core/sui-plugin.js +1 -1
  108. package/lib/core/sui-plugin.js.map +1 -1
  109. package/lib/error.js +2 -2
  110. package/lib/error.js.map +1 -1
  111. package/lib/eth/account-processor-state.d.ts +5 -0
  112. package/lib/eth/account-processor-state.js +9 -0
  113. package/lib/eth/account-processor-state.js.map +1 -0
  114. package/lib/{core → eth}/account-processor.d.ts +4 -8
  115. package/lib/{core → eth}/account-processor.js +33 -42
  116. package/lib/eth/account-processor.js.map +1 -0
  117. package/lib/{core → eth}/base-processor-template.d.ts +7 -8
  118. package/lib/{core → eth}/base-processor-template.js +3 -3
  119. package/lib/eth/base-processor-template.js.map +1 -0
  120. package/lib/{core → eth}/base-processor.d.ts +7 -7
  121. package/lib/{core → eth}/base-processor.js +13 -18
  122. package/lib/eth/base-processor.js.map +1 -0
  123. package/lib/{binds.d.ts → eth/binds.d.ts} +4 -3
  124. package/lib/{binds.js → eth/binds.js} +3 -3
  125. package/lib/eth/binds.js.map +1 -0
  126. package/lib/{core → eth}/eth-plugin.d.ts +2 -2
  127. package/lib/{core → eth}/eth-plugin.js +19 -13
  128. package/lib/eth/eth-plugin.js.map +1 -0
  129. package/lib/{core → eth}/generic-processor.d.ts +3 -3
  130. package/lib/{core → eth}/generic-processor.js +5 -5
  131. package/lib/eth/generic-processor.js.map +1 -0
  132. package/lib/eth/index.d.ts +6 -0
  133. package/lib/eth/index.js +15 -0
  134. package/lib/eth/index.js.map +1 -0
  135. package/lib/eth/provider.d.ts +4 -0
  136. package/lib/eth/provider.js +74 -0
  137. package/lib/eth/provider.js.map +1 -0
  138. package/lib/{core → eth}/trace.d.ts +2 -2
  139. package/lib/{core → eth}/trace.js +0 -0
  140. package/lib/eth/trace.js.map +1 -0
  141. package/lib/index.d.ts +2 -2
  142. package/lib/index.js +7 -23
  143. package/lib/index.js.map +1 -1
  144. package/lib/target-ethers-sentio/event-handler.d.ts +1 -0
  145. package/lib/target-ethers-sentio/event-handler.js +21 -5
  146. package/lib/target-ethers-sentio/event-handler.js.map +1 -1
  147. package/lib/target-ethers-sentio/file.js +59 -57
  148. package/lib/target-ethers-sentio/file.js.map +1 -1
  149. package/lib/target-ethers-sentio/functions-handler.js +7 -4
  150. package/lib/target-ethers-sentio/functions-handler.js.map +1 -1
  151. package/lib/target-ethers-sentio/index.d.ts +1 -1
  152. package/lib/target-ethers-sentio/index.js +3 -5
  153. package/lib/target-ethers-sentio/index.js.map +1 -1
  154. package/lib/target-ethers-sentio/view-function.js +15 -15
  155. package/lib/target-ethers-sentio/view-function.js.map +1 -1
  156. package/lib/testing/metric-utils.js +2 -2
  157. package/lib/testing/metric-utils.js.map +1 -1
  158. package/lib/testing/test-processor-server.d.ts +11 -11
  159. package/lib/testing/test-processor-server.js +7 -12
  160. package/lib/testing/test-processor-server.js.map +1 -1
  161. package/lib/testing/test-provider.js +1 -6
  162. package/lib/testing/test-provider.js.map +1 -1
  163. package/lib/utils/conversion.d.ts +2 -2
  164. package/lib/utils/conversion.js +12 -5
  165. package/lib/utils/conversion.js.map +1 -1
  166. package/lib/utils/dex-price.d.ts +1 -1
  167. package/lib/utils/dex-price.js +5 -6
  168. package/lib/utils/dex-price.js.map +1 -1
  169. package/lib/utils/dex-price.test.js.map +1 -1
  170. package/lib/utils/erc20.test.js.map +1 -1
  171. package/lib/utils/index.js +5 -27
  172. package/lib/utils/index.js.map +1 -1
  173. package/lib/utils/token.d.ts +2 -3
  174. package/lib/utils/token.js +5 -6
  175. package/lib/utils/token.js.map +1 -1
  176. package/lib/webpack.config.js +1 -1
  177. package/package.json +7 -13
  178. package/src/builtin/eacaggregatorproxy/test-utils.ts +13 -9
  179. package/src/builtin/erc1155/test-utils.ts +13 -9
  180. package/src/builtin/erc20/test-utils.ts +10 -7
  181. package/src/builtin/erc20bytes/test-utils.ts +7 -5
  182. package/src/builtin/erc721/test-utils.ts +10 -7
  183. package/src/builtin/internal/EACAggregatorProxy.ts +20 -815
  184. package/src/builtin/internal/ERC1155.ts +20 -483
  185. package/src/builtin/internal/ERC20.ts +15 -641
  186. package/src/builtin/internal/ERC20Bytes.ts +13 -357
  187. package/src/builtin/internal/ERC721.ts +15 -601
  188. package/src/builtin/internal/WETH9.ts +20 -439
  189. package/src/builtin/internal/common.ts +33 -33
  190. package/src/builtin/internal/eacaggregatorproxy_processor.ts +344 -425
  191. package/src/builtin/internal/erc1155_processor.ts +202 -209
  192. package/src/builtin/internal/erc20_processor.ts +191 -225
  193. package/src/builtin/internal/erc20bytes_processor.ts +136 -165
  194. package/src/builtin/internal/erc721_processor.ts +218 -242
  195. package/src/builtin/internal/factories/EACAggregatorProxy__factory.ts +2 -3
  196. package/src/builtin/internal/factories/ERC1155__factory.ts +2 -3
  197. package/src/builtin/internal/factories/ERC20Bytes__factory.ts +2 -3
  198. package/src/builtin/internal/factories/ERC20__factory.ts +2 -3
  199. package/src/builtin/internal/factories/ERC721__factory.ts +2 -3
  200. package/src/builtin/internal/factories/WETH9__factory.ts +2 -3
  201. package/src/builtin/internal/weth9_processor.ts +176 -208
  202. package/src/builtin/weth9/test-utils.ts +13 -9
  203. package/src/core/big-decimal.ts +11 -0
  204. package/src/core/bind-options.ts +2 -3
  205. package/src/core/context.ts +14 -13
  206. package/src/core/core-plugin.ts +1 -1
  207. package/src/core/index.ts +0 -6
  208. package/src/core/numberish.ts +39 -40
  209. package/src/core/sui-plugin.ts +1 -1
  210. package/src/error.ts +1 -1
  211. package/src/eth/account-processor-state.ts +6 -0
  212. package/src/{core → eth}/account-processor.ts +40 -50
  213. package/src/{core → eth}/base-processor-template.ts +11 -12
  214. package/src/{core → eth}/base-processor.ts +37 -31
  215. package/src/{binds.ts → eth/binds.ts} +6 -5
  216. package/src/{core → eth}/eth-plugin.ts +19 -12
  217. package/src/{core → eth}/generic-processor.ts +5 -5
  218. package/src/eth/index.ts +6 -0
  219. package/src/eth/provider.ts +82 -0
  220. package/src/{core → eth}/trace.ts +2 -3
  221. package/src/index.ts +2 -3
  222. package/src/target-ethers-sentio/event-handler.ts +22 -5
  223. package/src/target-ethers-sentio/file.ts +65 -65
  224. package/src/target-ethers-sentio/functions-handler.ts +8 -4
  225. package/src/target-ethers-sentio/index.ts +1 -1
  226. package/src/target-ethers-sentio/view-function.ts +17 -18
  227. package/src/testing/metric-utils.ts +2 -2
  228. package/src/testing/test-processor-server.ts +23 -24
  229. package/src/testing/test-provider.ts +2 -7
  230. package/src/utils/conversion.ts +12 -5
  231. package/src/utils/dex-price.ts +3 -3
  232. package/src/utils/token.ts +10 -11
  233. package/src/webpack.config.js +1 -1
  234. package/lib/binds.js.map +0 -1
  235. package/lib/core/account-processor.js.map +0 -1
  236. package/lib/core/base-processor-template.js.map +0 -1
  237. package/lib/core/base-processor.js.map +0 -1
  238. package/lib/core/eth-plugin.js.map +0 -1
  239. package/lib/core/generic-processor.js.map +0 -1
  240. package/lib/core/trace.js.map +0 -1
@@ -15,8 +15,8 @@ import {
15
15
  } from '@sentio/protos'
16
16
 
17
17
  import { ServerError, Status } from 'nice-grpc'
18
- import { ProcessorState } from '../binds'
19
- import { AccountProcessorState } from './account-processor'
18
+ import { ProcessorState } from './binds'
19
+ import { AccountProcessorState } from './account-processor-state'
20
20
  import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template'
21
21
 
22
22
  export class EthPlugin extends Plugin {
@@ -26,7 +26,7 @@ export class EthPlugin extends Plugin {
26
26
  private traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[] = []
27
27
  private blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[] = []
28
28
 
29
- configure(config: ProcessConfigResponse): void {
29
+ async configure(config: ProcessConfigResponse) {
30
30
  // This syntax is to copy values instead of using references
31
31
  config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]
32
32
 
@@ -93,16 +93,18 @@ export class EthPlugin extends Plugin {
93
93
  }
94
94
 
95
95
  for (const filter of eventsHandler.filters) {
96
- if (!filter.topics) {
97
- throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
98
- }
96
+ const topics = await filter.getTopicFilter()
97
+
98
+ // if (!filter.topics) {
99
+ // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
100
+ // }
99
101
  const logFilter: LogFilter = {
100
102
  addressType: undefined,
101
103
  address: contractConfig.contract?.address,
102
104
  topics: [],
103
105
  }
104
106
 
105
- for (const ts of filter.topics) {
107
+ for (const ts of topics) {
106
108
  let hashes: string[] = []
107
109
  if (Array.isArray(ts)) {
108
110
  hashes = hashes.concat(ts)
@@ -141,16 +143,21 @@ export class EthPlugin extends Plugin {
141
143
  }
142
144
 
143
145
  for (const filter of eventsHandler.filters) {
144
- if (!filter.topics) {
145
- throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
146
+ const topics = await filter.getTopicFilter()
147
+ // if (!filter.topics) {
148
+ // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')
149
+ // }
150
+ let address = undefined
151
+ if (filter.address) {
152
+ address = filter.address.toString()
146
153
  }
147
154
  const logFilter: LogFilter = {
148
155
  addressType: filter.addressType,
149
- address: filter.address,
156
+ address,
150
157
  topics: [],
151
158
  }
152
159
 
153
- for (const ts of filter.topics) {
160
+ for (const ts of topics) {
154
161
  let hashes: string[] = []
155
162
  if (Array.isArray(ts)) {
156
163
  hashes = hashes.concat(ts)
@@ -184,7 +191,7 @@ export class EthPlugin extends Plugin {
184
191
  }
185
192
  }
186
193
 
187
- start(request: StartRequest) {
194
+ async start(request: StartRequest) {
188
195
  for (const instance of request.templateInstances) {
189
196
  const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId]
190
197
  if (!template) {
@@ -1,9 +1,9 @@
1
- import { BaseContract } from '@ethersproject/contracts'
2
- import { BoundContractView, ContractView } from './context'
3
- import { BindOptions } from './bind-options'
1
+ import { BaseContract } from 'ethers'
2
+ import { BoundContractView, ContractView } from '../core/context'
3
+ import { BindOptions } from '../core/bind-options'
4
4
  import { BaseProcessor } from './base-processor'
5
- import { getProvider } from '@sentio/runtime'
6
- import { addProcessor } from '../binds'
5
+ import { getProvider } from './provider'
6
+ import { addProcessor } from './binds'
7
7
 
8
8
  export class GenericProcessor extends BaseProcessor<
9
9
  BaseContract,
@@ -0,0 +1,6 @@
1
+ export { BaseProcessor } from './base-processor'
2
+ export { GenericProcessor } from './generic-processor'
3
+ export { BaseProcessorTemplate } from './base-processor-template'
4
+ export { getProvider, DummyProvider } from './provider'
5
+ export type { TypedCallTrace, Trace } from './trace'
6
+ export { EthPlugin } from './eth-plugin'
@@ -0,0 +1,82 @@
1
+ import { Provider, Network, JsonRpcProvider } from 'ethers'
2
+ import { Networkish } from 'ethers/providers'
3
+
4
+ import PQueue from 'p-queue'
5
+ import { Endpoints } from '@sentio/runtime'
6
+
7
+ export const DummyProvider = new JsonRpcProvider('', Network.from(1))
8
+
9
+ const providers = new Map<string, JsonRpcProvider>()
10
+
11
+ export function getProvider(networkish?: Networkish): Provider {
12
+ if (!networkish) {
13
+ networkish = 1
14
+ }
15
+ const network = Network.from(networkish)
16
+ // TODO check if other key needed
17
+
18
+ const address = Endpoints.INSTANCE.chainServer.get(network.chainId.toString())
19
+ const key = network.chainId.toString() + '-' + address
20
+ let provider = providers.get(key)
21
+
22
+ if (provider) {
23
+ return provider
24
+ }
25
+
26
+ if (address === undefined) {
27
+ throw Error(
28
+ 'Provider not found for chain ' +
29
+ network.chainId +
30
+ ', configured chains: ' +
31
+ [...Endpoints.INSTANCE.chainServer.keys()].join(' ')
32
+ )
33
+ }
34
+ provider = new QueuedStaticJsonRpcProvider(address, network, Endpoints.INSTANCE.concurrency)
35
+ providers.set(network.chainId.toString(), provider)
36
+ return provider
37
+ }
38
+
39
+ // export function setProvider(config: Record<string, ChainConfig>, concurrency = 4, useChainServer = false) {
40
+ // Endpoints.INSTANCE.providers = new Map<bigint, Provider>()
41
+ //
42
+ // for (const chainIdStr in config) {
43
+ // if (isNaN(Number.parseInt(chainIdStr))) {
44
+ // continue
45
+ // }
46
+ //
47
+ // const chainConfig = config[chainIdStr]
48
+ // const chainId = BigInt(chainIdStr)
49
+ //
50
+ // // let providers: StaticJsonRpcProvider[] = []
51
+ // // for (const http of chainConfig.Https) {
52
+ // // providers.push(new StaticJsonRpcProvider(http, chainId))
53
+ // // }
54
+ // // random shuffle
55
+ // // providers = providers.sort(() => Math.random() - 0.5)
56
+ //
57
+ // // const provider = new FallbackProvider(providers)
58
+ //
59
+ // let rpcAddress = ''
60
+ // if (useChainServer && chainConfig.ChainServer) {
61
+ // rpcAddress = chainConfig.ChainServer
62
+ // } else {
63
+ // const idx = Math.floor(Math.random() * chainConfig.Https.length)
64
+ // rpcAddress = chainConfig.Https[idx]
65
+ // }
66
+ //
67
+ // Endpoints.INSTANCE.providers.set(chainId, provider)
68
+ // }
69
+ // }
70
+
71
+ class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
72
+ executor: PQueue
73
+
74
+ constructor(url: string, network: Networkish, concurrency: number) {
75
+ super(url, Network.from(network))
76
+ this.executor = new PQueue({ concurrency: concurrency })
77
+ }
78
+
79
+ send(method: string, params: Array<any>): Promise<any> {
80
+ return this.executor.add(() => super.send(method, params))
81
+ }
82
+ }
@@ -1,13 +1,12 @@
1
1
  // https://github.com/openethereum/parity-ethereum/blob/55c90d4016505317034e3e98f699af07f5404b63/rpc/src/v1/types/trace.rs#L482
2
- import { Result } from '@ethersproject/abi'
2
+ import { Result } from 'ethers'
3
3
 
4
- export interface TypedCallTrace<TArgsArray extends Array<any> = any, TArgsObject = any> extends Trace {
4
+ export interface TypedCallTrace<TArgsArray extends Array<any> = any, TArgsObject = any> {
5
5
  args: TArgsArray & TArgsObject
6
6
  }
7
7
 
8
8
  export interface Trace {
9
9
  args?: Result
10
-
11
10
  action: TraceAction
12
11
  blockHash: string
13
12
  blockNumber: number
package/src/index.ts CHANGED
@@ -1,13 +1,12 @@
1
- export { getProvider, setProvider, DummyProvider } from '@sentio/runtime'
2
1
  export { transformEtherError, EthersError } from './error'
3
2
 
4
- export { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds'
3
+ export { getProcessor, addProcessor, getContractByABI, addContractByABI } from './eth/binds'
5
4
 
6
5
  // TODO maybe remove this
7
6
  export * from '@sentio/protos'
8
7
 
9
8
  export * from './core'
9
+ export * from './eth'
10
10
 
11
11
  export * from './utils/chain'
12
-
13
12
  // export * from './api'
@@ -1,5 +1,6 @@
1
- import { EventDeclaration, getFullSignatureAsSymbolForEvent } from 'typechain'
1
+ import { EventDeclaration, Contract, getFullSignatureAsSymbolForEvent } from 'typechain'
2
2
  import { getFullSignatureForEventPatched } from './types'
3
+ import { generateEventInputs } from '@sentio/ethers-v6/dist/codegen/events'
3
4
 
4
5
  export function generateEventHandler(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {
5
6
  const eventName = includeArgTypes ? getFullSignatureAsSymbolForEvent(event) : event.name
@@ -13,10 +14,7 @@ export function generateEventHandler(event: EventDeclaration, contractName: stri
13
14
  fetchConfig?: EthFetchConfig
14
15
  ) {
15
16
  if (!filter) {
16
- // @ts-ignore
17
- filter = ${contractName}Processor.filters[
18
- // @ts-ignore
19
- '${filterName}'](${event.inputs.map(() => 'null').join(',')})
17
+ filter = templateContract.filters['${filterName}'](${event.inputs.map(() => 'null').join(',')})
20
18
  }
21
19
  return super.onEvent(handler, filter!, fetchConfig)
22
20
  }
@@ -30,3 +28,22 @@ export function generateEventHandlers(events: EventDeclaration[], contractName:
30
28
  return events.map((e) => generateEventHandler(e, contractName, true)).join('\n')
31
29
  }
32
30
  }
31
+
32
+ function generateEventFilter(event: EventDeclaration, includeArgTypes: boolean): string {
33
+ const eventName = includeArgTypes ? getFullSignatureAsSymbolForEvent(event) : event.name
34
+
35
+ const filterName = getFullSignatureForEventPatched(event)
36
+ return `
37
+ ${eventName}(${generateEventInputs(event.inputs)}) { return templateContract.filters['${filterName}'](${event.inputs
38
+ .map((i) => i.name)
39
+ .join(',')}) }
40
+ `
41
+ }
42
+
43
+ export function generateEventFilters(events: EventDeclaration[]): string[] {
44
+ if (events.length === 1) {
45
+ return [generateEventFilter(events[0], false)]
46
+ } else {
47
+ return events.map((e) => generateEventFilter(e, true))
48
+ }
49
+ }
@@ -5,10 +5,10 @@ import {
5
5
  getFullSignatureAsSymbolForEvent,
6
6
  } from 'typechain'
7
7
 
8
- import { reservedKeywords } from '@typechain/ethers-v5/dist/codegen/reserved-keywords'
8
+ import { reservedKeywords } from '@sentio/ethers-v6/dist/codegen/reserved-keywords'
9
9
  import { getFullSignatureForEvent } from 'typechain/dist/utils/signatures'
10
10
  import { codegenCallTraceTypes, generateCallHandlers } from './functions-handler'
11
- import { generateEventHandlers } from './event-handler'
11
+ import { generateEventFilters, generateEventHandlers } from './event-handler'
12
12
  import { generateBoundViewFunctions, generateViewFunctions } from './view-function'
13
13
 
14
14
  export function codeGenIndex(contract: Contract): string {
@@ -22,7 +22,7 @@ export function codeGenSentioFile(contract: Contract): string {
22
22
  const source = `
23
23
  ${Object.values(contract.functions).map(codegenCallTraceTypes).join('\n')}
24
24
 
25
- const templateContract = ${contract.name}__factory.connect("", DummyProvider)
25
+ const templateContract = ${contract.name}__factory.connect("0x0", DummyProvider)
26
26
 
27
27
  export class ${contract.name}ContractView extends ContractView<${contract.name}> {
28
28
  constructor (contract: ${contract.name}) {
@@ -35,76 +35,76 @@ export function codeGenSentioFile(contract: Contract): string {
35
35
  .join('\n')}
36
36
  }
37
37
 
38
- export class ${contract.name}BoundContractView extends BoundContractView<${contract.name}, ${
39
- contract.name
40
- }ContractView> {
41
- // constructor (contract: ${contract.name}) {
42
- // super(contract);
43
- // }
44
-
45
- ${Object.values(contract.functions)
46
- .filter((f) => !reservedKeywords.has(f[0].name))
47
- .map((fs) => generateBoundViewFunctions(fs))
48
- .join('\n')}
38
+ export class ${contract.name}BoundContractView extends BoundContractView<${contract.name},
39
+ ${contract.name}ContractView> {
40
+ ${Object.values(contract.functions)
41
+ .filter((f) => !reservedKeywords.has(f[0].name))
42
+ .map((fs) => generateBoundViewFunctions(fs))
43
+ .join('\n')}
49
44
  }
50
45
 
51
- export type ${contract.name}Context = ContractContext<${contract.name}, ${contract.name}BoundContractView>
52
-
53
- export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${contract.name}, ${
54
- contract.name
55
- }BoundContractView> {
56
- bindInternal(options: BindOptions) {
57
- if (!options.name) {
58
- options.name = "${contract.name}"
59
- }
60
- let processor = getProcessor(options) as ${contract.name}Processor
61
- if (!processor) {
62
- processor = new ${contract.name}Processor(options)
63
- addProcessor(options, processor)
64
- }
65
- return processor
66
- }
46
+ export type ${contract.name}Context = ContractContext<${contract.name}, ${contract.name}BoundContractView>
67
47
 
48
+ export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {
68
49
  ${Object.values(contract.events)
69
50
  .map((events) => generateEventHandlers(events, contract.name))
70
51
  .join('\n')}
71
-
52
+
72
53
  ${Object.values(contract.functions)
73
- .map((functions) => {
74
- generateCallHandlers(functions, contract.name)
75
- })
54
+ .map((f) => generateCallHandlers(f, contract.name))
76
55
  .join('\n')}
77
- }
78
56
 
79
- export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {
80
- ${Object.values(contract.events)
81
- .map((events) => generateEventHandlers(events, contract.name))
82
- .join('\n')}
83
-
84
- ${Object.values(contract.functions)
85
- .map((f) => generateCallHandlers(f, contract.name))
86
- .join('\n')}
57
+ public static filters = {
58
+ ${Object.values(contract.events)
59
+ .map((events) => generateEventFilters(events))
60
+ .join(',')}
61
+ }
62
+
63
+ protected CreateBoundContractView(): ${contract.name}BoundContractView {
64
+ const view = get${contract.name}Contract(this.config.address, this.config.network)
65
+ return new ${contract.name}BoundContractView(view)
66
+ }
87
67
 
88
- public static filters = templateContract.filters
89
-
90
- protected CreateBoundContractView(): ${contract.name}BoundContractView {
91
- const view = get${contract.name}Contract(this.config.address, this.config.network)
92
- return new ${contract.name}BoundContractView(view)
68
+ public static bind(options: BindOptions): ${contract.name}Processor {
69
+ if (!options.name) {
70
+ options.name = "${contract.name}"
71
+ }
72
+ let processor = getProcessor(options) as ${contract.name}Processor
73
+ if (!processor) {
74
+ processor = new ${contract.name}Processor(options)
75
+ addProcessor(options, processor)
93
76
  }
77
+ return processor
78
+ }
79
+ }
94
80
 
95
- public static bind(options: BindOptions): ${contract.name}Processor {
96
- if (!options.name) {
97
- options.name = "${contract.name}"
98
- }
99
- let processor = getProcessor(options) as ${contract.name}Processor
100
- if (!processor) {
101
- processor = new ${contract.name}Processor(options)
102
- addProcessor(options, processor)
103
- }
104
- return processor
81
+ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${contract.name}, ${
82
+ contract.name
83
+ }BoundContractView> {
84
+ bindInternal(options: BindOptions) {
85
+ if (!options.name) {
86
+ options.name = "${contract.name}"
87
+ }
88
+ let processor = getProcessor(options) as ${contract.name}Processor
89
+ if (!processor) {
90
+ processor = new ${contract.name}Processor(options)
91
+ addProcessor(options, processor)
105
92
  }
93
+ return processor
106
94
  }
107
95
 
96
+ ${Object.values(contract.events)
97
+ .map((events) => generateEventHandlers(events, contract.name))
98
+ .join('\n')}
99
+
100
+ ${Object.values(contract.functions)
101
+ .map((functions) => {
102
+ generateCallHandlers(functions, contract.name)
103
+ })
104
+ .join('\n')}
105
+ }
106
+
107
+
108
108
  export function get${contract.name}Contract(address: string, network: Networkish = 1): ${contract.name}ContractView {
109
109
  let contract = getContractByABI("${contract.name}", address, network) as ${contract.name}ContractView
110
110
  if (!contract) {
@@ -143,8 +143,8 @@ export function codeGenSentioFile(contract: Contract): string {
143
143
 
144
144
  const imports = createImportsForUsedIdentifiers(
145
145
  {
146
- ethers: ['BigNumber', 'BigNumberish', 'CallOverrides', 'BytesLike'],
147
- '@ethersproject/providers': ['Networkish'],
146
+ ethers: ['BigNumberish', 'Overrides', 'BytesLike'],
147
+ 'ethers/providers': ['Networkish'],
148
148
  '@sentio/sdk': [
149
149
  'addContractByABI',
150
150
  'getContractByABI',
@@ -152,6 +152,7 @@ export function codeGenSentioFile(contract: Contract): string {
152
152
  'getProcessor',
153
153
  'getProvider',
154
154
  'transformEtherError',
155
+ 'Trace',
155
156
  'BindOptions',
156
157
  'BaseProcessor',
157
158
  'BaseProcessorTemplate',
@@ -198,7 +199,7 @@ export function codeGenTestUtilsFile(contract: Contract): string {
198
199
 
199
200
  const imports = createImportsForUsedIdentifiers(
200
201
  {
201
- '@ethersproject/providers': ['Log'],
202
+ 'ethers/providers': ['LogParams'],
202
203
  '.': [
203
204
  `get${contract.name}Contract`,
204
205
  ...Object.values(contract.events).flatMap((events) => {
@@ -218,23 +219,22 @@ export function codeGenTestUtilsFile(contract: Contract): string {
218
219
 
219
220
  function generateMockEventLogFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {
220
221
  let eventName = event.name
221
- let eventNameWithSignature = event.name
222
222
  if (includeArgTypes) {
223
223
  eventName = getFullSignatureAsSymbolForEvent(event) + '_'
224
- eventNameWithSignature = getFullSignatureForEvent(event)
225
224
  }
226
225
 
227
226
  const eventArgs = event.inputs.map((input, i) => `event.${input.name ?? `arg${i.toString()}`}`)
228
227
 
229
228
  return `
230
- export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): Log {
229
+ export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): LogParams {
231
230
  const contract = get${contractName}Contract(contractAddress)
232
231
  const encodedLog = contract.rawContract.interface.encodeEventLog(
233
- contract.rawContract.interface.getEvent('${eventNameWithSignature}'),
232
+ '${getFullSignatureForEvent(event)}',
234
233
  [${eventArgs.join(', ')}]
235
234
  )
236
235
  return {
237
236
  ...mockField,
237
+ index: 0,
238
238
  address: contractAddress,
239
239
  data: encodedLog.data,
240
240
  topics: encodedLog.topics,
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  generateOutputComplexTypeAsArray,
3
3
  generateOutputComplexTypesAsObject,
4
- } from '@typechain/ethers-v5/dist/codegen/types'
4
+ } from '@sentio/ethers-v6/dist/codegen/types'
5
+ import { keccak256 } from 'ethers'
5
6
  import { FunctionDeclaration, getSignatureForFn } from 'typechain'
6
- import { utils } from 'ethers'
7
+ // import { utils } from 'ethers'
7
8
  import { getFullSignatureAsSymbolForFunction } from './types'
8
9
 
9
10
  export function generateCallHandlers(fns: FunctionDeclaration[], contractName: string): string {
@@ -32,13 +33,16 @@ function codegenCallTraceType(fn: FunctionDeclaration, overloadedName?: string):
32
33
  return `
33
34
  export interface ${identifier}CallObject ${objectOutput}
34
35
 
35
- export type ${identifier}CallTrace = TypedCallTrace<${arrayOutput}, ${identifier}CallObject>
36
+ export type ${identifier}CallTrace = TypedCallTrace<${arrayOutput}, ${identifier}CallObject> & Trace
36
37
  `
37
38
  }
38
39
 
39
40
  function generateCallHandler(fn: FunctionDeclaration, contractName: string, overloadedName?: string): string {
40
41
  const signature = getSignatureForFn(fn)
41
- const sighash = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10)
42
+ // utils.toUtf8Bytes(signature))
43
+
44
+ const test = new TextEncoder().encode(signature)
45
+ const sighash = keccak256(test).substring(0, 10)
42
46
 
43
47
  return `
44
48
  onCall${capitalizeFirstChar(overloadedName ?? fn.name)}(
@@ -1,4 +1,4 @@
1
- import Ethers from '@typechain/ethers-v5'
1
+ import Ethers from '@sentio/ethers-v6'
2
2
  import { Config, extractAbi, extractDocumentation, FileDescription, parse, shortenFullJsonFilePath } from 'typechain'
3
3
  import { dirname, join, relative } from 'path'
4
4
  import { codeGenIndex, codeGenSentioFile, codeGenTestUtilsFile } from './file'
@@ -1,6 +1,6 @@
1
1
  // https://github.com/dethcrypto/TypeChain/blob/015abb28bd22826611051f27e0ec96a00f9a0b61/packages/target-ethers-v5/src/codegen/functions.ts#L54
2
2
  import { FunctionDeclaration } from 'typechain'
3
- import { generateInputTypes, generateOutputTypes } from '@typechain/ethers-v5/dist/codegen/types'
3
+ import { generateInputTypes, generateOutputTypes } from '@sentio/ethers-v6/dist/codegen/types'
4
4
  import { getFullSignatureAsSymbolForFunction, getFullSignatureForFunction } from './types'
5
5
 
6
6
  function generateReturnTypes(fn: FunctionDeclaration) {
@@ -20,20 +20,22 @@ export function generateViewFunction(fn: FunctionDeclaration, includeArgTypes: b
20
20
  return ''
21
21
  }
22
22
  const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name
23
- const call = includeArgTypes ? 'this.contract["' + getFullSignatureForFunction(fn) + '"]' : 'this.contract.' + fn.name
24
-
23
+ const call = 'this.contract.getFunction("' + getFullSignatureForFunction(fn) + '")'
24
+ // if (overrides) {
25
+ // return await ${call}(${
26
+ // fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
27
+ // } overrides)
28
+ // } else {
29
+ // return await ${call}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})
30
+ // }
25
31
  return `
26
32
  async ${declName}(${generateInputTypes(fn.inputs, {
27
33
  useStructs: true,
28
- })}overrides?: CallOverrides): ${generateReturnTypes(fn)} {
29
- try {
30
- if (overrides) {
31
- return await ${call}(${
34
+ })}overrides?: Overrides): ${generateReturnTypes(fn)} {
35
+ try {
36
+ return await ${call}(${
32
37
  fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
33
- } overrides)
34
- } else {
35
- return await ${call}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})
36
- }
38
+ } overrides || {})
37
39
  } catch (e) {
38
40
  throw transformEtherError(e, undefined)
39
41
  }
@@ -57,20 +59,17 @@ export function generateBoundViewFunction(fn: FunctionDeclaration, includeArgTyp
57
59
  return `
58
60
  async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
59
61
  useStructs: true,
60
- })}overrides?: CallOverrides): ${generateReturnTypes(fn)} {
62
+ })}overrides?: Overrides): ${generateReturnTypes(fn)} {
61
63
  try {
62
64
  if (!overrides && this.context) {
63
65
  overrides = {
64
66
  blockTag: toBlockTag(this.context.blockNumber),
65
67
  }
66
68
  }
67
- if (overrides) {
68
- return await this.view.${declName}(${
69
+ return await this.view.${declName}(${
69
70
  fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
70
- } overrides)
71
- } else {
72
- return await this.view.${declName}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})
73
- }
71
+ } overrides || {})
72
+
74
73
  } catch (e) {
75
74
  throw transformEtherError(e, this.context)
76
75
  }
@@ -1,6 +1,6 @@
1
1
  import { MetricValue, ProcessResult } from '@sentio/protos'
2
2
  import { Numberish, BigDecimal } from '../core'
3
- import { BigNumber } from 'ethers'
3
+ import { bytesToBigInt } from '../utils/conversion'
4
4
 
5
5
  export function MetricValueToNumber(v: Partial<MetricValue> | undefined): Numberish | undefined {
6
6
  if (v === undefined) {
@@ -11,7 +11,7 @@ export function MetricValueToNumber(v: Partial<MetricValue> | undefined): Number
11
11
  return v.doubleValue
12
12
  }
13
13
  if (v.bigInteger !== undefined) {
14
- let intValue = BigNumber.from(v.bigInteger.data).toBigInt()
14
+ let intValue = bytesToBigInt(v.bigInteger.data)
15
15
  if (v.bigInteger.negative) {
16
16
  intValue = -intValue
17
17
  }