@sentio/sdk 2.0.0-rc.3 → 2.0.0-rc.5

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 (295) hide show
  1. package/lib/builtin/eacaggregatorproxy/index.d.ts +3 -2
  2. package/lib/builtin/eacaggregatorproxy/index.js +3 -5
  3. package/lib/builtin/eacaggregatorproxy/index.js.map +1 -1
  4. package/lib/builtin/eacaggregatorproxy/test-utils.d.ts +1 -1
  5. package/lib/builtin/eacaggregatorproxy/test-utils.js +9 -16
  6. package/lib/builtin/eacaggregatorproxy/test-utils.js.map +1 -1
  7. package/lib/builtin/erc1155/index.d.ts +3 -2
  8. package/lib/builtin/erc1155/index.js +3 -5
  9. package/lib/builtin/erc1155/index.js.map +1 -1
  10. package/lib/builtin/erc1155/test-utils.d.ts +1 -1
  11. package/lib/builtin/erc1155/test-utils.js +9 -16
  12. package/lib/builtin/erc1155/test-utils.js.map +1 -1
  13. package/lib/builtin/erc20/index.d.ts +3 -2
  14. package/lib/builtin/erc20/index.js +3 -5
  15. package/lib/builtin/erc20/index.js.map +1 -1
  16. package/lib/builtin/erc20/test-utils.d.ts +1 -1
  17. package/lib/builtin/erc20/test-utils.js +7 -13
  18. package/lib/builtin/erc20/test-utils.js.map +1 -1
  19. package/lib/builtin/erc20bytes/index.d.ts +3 -2
  20. package/lib/builtin/erc20bytes/index.js +3 -5
  21. package/lib/builtin/erc20bytes/index.js.map +1 -1
  22. package/lib/builtin/erc20bytes/test-utils.d.ts +1 -1
  23. package/lib/builtin/erc20bytes/test-utils.js +5 -10
  24. package/lib/builtin/erc20bytes/test-utils.js.map +1 -1
  25. package/lib/builtin/erc721/index.d.ts +3 -2
  26. package/lib/builtin/erc721/index.js +3 -5
  27. package/lib/builtin/erc721/index.js.map +1 -1
  28. package/lib/builtin/erc721/test-utils.d.ts +1 -1
  29. package/lib/builtin/erc721/test-utils.js +7 -13
  30. package/lib/builtin/erc721/test-utils.js.map +1 -1
  31. package/lib/builtin/index.d.ts +8 -4
  32. package/lib/builtin/index.js +8 -8
  33. package/lib/builtin/index.js.map +1 -1
  34. package/lib/builtin/internal/EACAggregatorProxy.d.ts +1 -1
  35. package/lib/builtin/internal/EACAggregatorProxy.js +1 -2
  36. package/lib/builtin/internal/EACAggregatorProxy.js.map +1 -1
  37. package/lib/builtin/internal/ERC1155.d.ts +1 -1
  38. package/lib/builtin/internal/ERC1155.js +1 -2
  39. package/lib/builtin/internal/ERC1155.js.map +1 -1
  40. package/lib/builtin/internal/ERC20.d.ts +1 -1
  41. package/lib/builtin/internal/ERC20.js +1 -2
  42. package/lib/builtin/internal/ERC20.js.map +1 -1
  43. package/lib/builtin/internal/ERC20Bytes.d.ts +1 -1
  44. package/lib/builtin/internal/ERC20Bytes.js +1 -2
  45. package/lib/builtin/internal/ERC20Bytes.js.map +1 -1
  46. package/lib/builtin/internal/ERC721.d.ts +1 -1
  47. package/lib/builtin/internal/ERC721.js +1 -2
  48. package/lib/builtin/internal/ERC721.js.map +1 -1
  49. package/lib/builtin/internal/WETH9.d.ts +1 -1
  50. package/lib/builtin/internal/WETH9.js +1 -2
  51. package/lib/builtin/internal/WETH9.js.map +1 -1
  52. package/lib/builtin/internal/common.js +1 -2
  53. package/lib/builtin/internal/common.js.map +1 -1
  54. package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +6 -6
  55. package/lib/builtin/internal/eacaggregatorproxy_processor.js +69 -77
  56. package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
  57. package/lib/builtin/internal/erc1155_processor.d.ts +6 -6
  58. package/lib/builtin/internal/erc1155_processor.js +30 -38
  59. package/lib/builtin/internal/erc1155_processor.js.map +1 -1
  60. package/lib/builtin/internal/erc20_processor.d.ts +5 -5
  61. package/lib/builtin/internal/erc20_processor.js +39 -47
  62. package/lib/builtin/internal/erc20_processor.js.map +1 -1
  63. package/lib/builtin/internal/erc20bytes_processor.d.ts +4 -4
  64. package/lib/builtin/internal/erc20bytes_processor.js +33 -41
  65. package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
  66. package/lib/builtin/internal/erc721_processor.d.ts +5 -5
  67. package/lib/builtin/internal/erc721_processor.js +42 -50
  68. package/lib/builtin/internal/erc721_processor.js.map +1 -1
  69. package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js +4 -8
  70. package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js.map +1 -1
  71. package/lib/builtin/internal/factories/ERC1155__factory.js +4 -8
  72. package/lib/builtin/internal/factories/ERC1155__factory.js.map +1 -1
  73. package/lib/builtin/internal/factories/ERC20Bytes__factory.js +4 -8
  74. package/lib/builtin/internal/factories/ERC20Bytes__factory.js.map +1 -1
  75. package/lib/builtin/internal/factories/ERC20__factory.js +4 -8
  76. package/lib/builtin/internal/factories/ERC20__factory.js.map +1 -1
  77. package/lib/builtin/internal/factories/ERC721__factory.js +4 -8
  78. package/lib/builtin/internal/factories/ERC721__factory.js.map +1 -1
  79. package/lib/builtin/internal/factories/WETH9__factory.js +4 -8
  80. package/lib/builtin/internal/factories/WETH9__factory.js.map +1 -1
  81. package/lib/builtin/internal/factories/index.d.ts +6 -6
  82. package/lib/builtin/internal/factories/index.js +6 -15
  83. package/lib/builtin/internal/factories/index.js.map +1 -1
  84. package/lib/builtin/internal/index.d.ts +13 -13
  85. package/lib/builtin/internal/index.js +7 -17
  86. package/lib/builtin/internal/index.js.map +1 -1
  87. package/lib/builtin/internal/weth9_processor.d.ts +6 -6
  88. package/lib/builtin/internal/weth9_processor.js +33 -41
  89. package/lib/builtin/internal/weth9_processor.js.map +1 -1
  90. package/lib/builtin/weth9/index.d.ts +3 -2
  91. package/lib/builtin/weth9/index.js +3 -5
  92. package/lib/builtin/weth9/index.js.map +1 -1
  93. package/lib/builtin/weth9/test-utils.d.ts +1 -1
  94. package/lib/builtin/weth9/test-utils.js +9 -16
  95. package/lib/builtin/weth9/test-utils.js.map +1 -1
  96. package/lib/core/base-context.d.ts +4 -4
  97. package/lib/core/base-context.js +7 -11
  98. package/lib/core/base-context.js.map +1 -1
  99. package/lib/core/big-decimal.js +3 -7
  100. package/lib/core/big-decimal.js.map +1 -1
  101. package/lib/core/bind-options.js +6 -13
  102. package/lib/core/bind-options.js.map +1 -1
  103. package/lib/core/context.d.ts +5 -5
  104. package/lib/core/context.js +14 -23
  105. package/lib/core/context.js.map +1 -1
  106. package/lib/core/core-plugin.js +9 -13
  107. package/lib/core/core-plugin.js.map +1 -1
  108. package/lib/core/event-tracker.d.ts +2 -2
  109. package/lib/core/event-tracker.js +6 -13
  110. package/lib/core/event-tracker.js.map +1 -1
  111. package/lib/core/exporter.d.ts +2 -2
  112. package/lib/core/exporter.js +4 -9
  113. package/lib/core/exporter.js.map +1 -1
  114. package/lib/core/index.d.ts +12 -9
  115. package/lib/core/index.js +12 -32
  116. package/lib/core/index.js.map +1 -1
  117. package/lib/core/logger.d.ts +2 -2
  118. package/lib/core/logger.js +7 -11
  119. package/lib/core/logger.js.map +1 -1
  120. package/lib/core/metadata.d.ts +4 -0
  121. package/lib/core/metadata.js +21 -7
  122. package/lib/core/metadata.js.map +1 -1
  123. package/lib/core/meter.d.ts +3 -7
  124. package/lib/core/meter.js +22 -57
  125. package/lib/core/meter.js.map +1 -1
  126. package/lib/core/meter.test.js.map +1 -1
  127. package/lib/core/numberish.d.ts +1 -1
  128. package/lib/core/numberish.js +12 -18
  129. package/lib/core/numberish.js.map +1 -1
  130. package/lib/core/numberish.test.js.map +1 -1
  131. package/lib/core/sui-plugin.js +12 -16
  132. package/lib/core/sui-plugin.js.map +1 -1
  133. package/lib/core/sui-processor.d.ts +1 -1
  134. package/lib/core/sui-processor.js +6 -12
  135. package/lib/core/sui-processor.js.map +1 -1
  136. package/lib/error.d.ts +1 -1
  137. package/lib/error.js +2 -7
  138. package/lib/error.js.map +1 -1
  139. package/lib/eth/account-processor-state.d.ts +1 -1
  140. package/lib/eth/account-processor-state.js +2 -6
  141. package/lib/eth/account-processor-state.js.map +1 -1
  142. package/lib/eth/account-processor.d.ts +7 -7
  143. package/lib/eth/account-processor.js +23 -27
  144. package/lib/eth/account-processor.js.map +1 -1
  145. package/lib/eth/base-processor-template.d.ts +5 -5
  146. package/lib/eth/base-processor-template.js +8 -14
  147. package/lib/eth/base-processor-template.js.map +1 -1
  148. package/lib/eth/base-processor.d.ts +4 -4
  149. package/lib/eth/base-processor.js +19 -26
  150. package/lib/eth/base-processor.js.map +1 -1
  151. package/lib/eth/binds.d.ts +3 -3
  152. package/lib/eth/binds.js +11 -19
  153. package/lib/eth/binds.js.map +1 -1
  154. package/lib/eth/eth-plugin.js +30 -34
  155. package/lib/eth/eth-plugin.js.map +1 -1
  156. package/lib/eth/generic-processor.d.ts +3 -3
  157. package/lib/eth/generic-processor.js +9 -13
  158. package/lib/eth/generic-processor.js.map +1 -1
  159. package/lib/{core → eth}/generic-processor.test.d.ts +0 -0
  160. package/lib/eth/generic-processor.test.js.map +1 -0
  161. package/lib/eth/index.d.ts +7 -6
  162. package/lib/eth/index.js +6 -14
  163. package/lib/eth/index.js.map +1 -1
  164. package/lib/eth/provider.js +12 -17
  165. package/lib/eth/provider.js.map +1 -1
  166. package/lib/eth/trace.js +1 -2
  167. package/lib/eth/trace.js.map +1 -1
  168. package/lib/index.d.ts +4 -5
  169. package/lib/index.js +5 -16
  170. package/lib/index.js.map +1 -1
  171. package/lib/promise-or-void.js +1 -2
  172. package/lib/target-ethers-sentio/{event-handler.js → event-handler.cjs} +4 -4
  173. package/lib/target-ethers-sentio/event-handler.cjs.map +1 -0
  174. package/lib/target-ethers-sentio/{event-handler.d.ts → event-handler.d.cts} +0 -0
  175. package/lib/target-ethers-sentio/{file.js → file.cjs} +19 -18
  176. package/lib/target-ethers-sentio/file.cjs.map +1 -0
  177. package/lib/target-ethers-sentio/{file.d.ts → file.d.cts} +0 -0
  178. package/lib/target-ethers-sentio/{functions-handler.js → functions-handler.cjs} +6 -7
  179. package/lib/target-ethers-sentio/functions-handler.cjs.map +1 -0
  180. package/lib/target-ethers-sentio/{functions-handler.d.ts → functions-handler.d.cts} +0 -0
  181. package/lib/target-ethers-sentio/{index.js → index.cjs} +8 -5
  182. package/lib/target-ethers-sentio/index.cjs.map +1 -0
  183. package/lib/target-ethers-sentio/{index.d.ts → index.d.cts} +0 -0
  184. package/lib/target-ethers-sentio/{types.js → types.cjs} +1 -1
  185. package/lib/target-ethers-sentio/types.cjs.map +1 -0
  186. package/lib/target-ethers-sentio/{types.d.ts → types.d.cts} +0 -0
  187. package/lib/target-ethers-sentio/{view-function.js → view-function.cjs} +5 -5
  188. package/lib/target-ethers-sentio/view-function.cjs.map +1 -0
  189. package/lib/target-ethers-sentio/{view-function.d.ts → view-function.d.cts} +0 -0
  190. package/lib/testing/index.d.ts +3 -2
  191. package/lib/testing/index.js +3 -10
  192. package/lib/testing/index.js.map +1 -1
  193. package/lib/testing/metric-utils.d.ts +1 -1
  194. package/lib/testing/metric-utils.js +7 -13
  195. package/lib/testing/metric-utils.js.map +1 -1
  196. package/lib/testing/test-processor-server.d.ts +3 -4
  197. package/lib/testing/test-processor-server.js +24 -29
  198. package/lib/testing/test-processor-server.js.map +1 -1
  199. package/lib/testing/test-provider.js +5 -9
  200. package/lib/testing/test-provider.js.map +1 -1
  201. package/lib/tsup.config.ts +22 -0
  202. package/lib/utils/chain.js +7 -12
  203. package/lib/utils/chain.js.map +1 -1
  204. package/lib/utils/conversion.d.ts +2 -2
  205. package/lib/utils/conversion.js +6 -12
  206. package/lib/utils/conversion.js.map +1 -1
  207. package/lib/utils/dex-price.js +14 -19
  208. package/lib/utils/dex-price.js.map +1 -1
  209. package/lib/utils/dex-price.test.js.map +1 -1
  210. package/lib/utils/erc20.test.js.map +1 -1
  211. package/lib/utils/index.d.ts +4 -4
  212. package/lib/utils/index.js +4 -8
  213. package/lib/utils/index.js.map +1 -1
  214. package/lib/utils/price.d.ts +11 -11
  215. package/lib/utils/price.js +10 -16
  216. package/lib/utils/price.js.map +1 -1
  217. package/lib/utils/token.d.ts +1 -1
  218. package/lib/utils/token.js +15 -21
  219. package/lib/utils/token.js.map +1 -1
  220. package/package.json +23 -19
  221. package/src/builtin/eacaggregatorproxy/index.ts +3 -2
  222. package/src/builtin/eacaggregatorproxy/test-utils.ts +1 -1
  223. package/src/builtin/erc1155/index.ts +3 -2
  224. package/src/builtin/erc1155/test-utils.ts +1 -1
  225. package/src/builtin/erc20/index.ts +3 -2
  226. package/src/builtin/erc20/test-utils.ts +1 -1
  227. package/src/builtin/erc20bytes/index.ts +3 -2
  228. package/src/builtin/erc20bytes/test-utils.ts +1 -1
  229. package/src/builtin/erc721/index.ts +3 -2
  230. package/src/builtin/erc721/test-utils.ts +1 -1
  231. package/src/builtin/index.ts +8 -4
  232. package/src/builtin/internal/EACAggregatorProxy.ts +1 -1
  233. package/src/builtin/internal/ERC1155.ts +1 -1
  234. package/src/builtin/internal/ERC20.ts +1 -1
  235. package/src/builtin/internal/ERC20Bytes.ts +1 -1
  236. package/src/builtin/internal/ERC721.ts +1 -1
  237. package/src/builtin/internal/WETH9.ts +1 -1
  238. package/src/builtin/internal/eacaggregatorproxy_processor.ts +2 -2
  239. package/src/builtin/internal/erc1155_processor.ts +2 -2
  240. package/src/builtin/internal/erc20_processor.ts +2 -2
  241. package/src/builtin/internal/erc20bytes_processor.ts +2 -2
  242. package/src/builtin/internal/erc721_processor.ts +2 -2
  243. package/src/builtin/internal/factories/index.ts +6 -6
  244. package/src/builtin/internal/index.ts +13 -13
  245. package/src/builtin/internal/weth9_processor.ts +2 -2
  246. package/src/builtin/weth9/index.ts +3 -2
  247. package/src/builtin/weth9/test-utils.ts +1 -1
  248. package/src/core/base-context.ts +4 -4
  249. package/src/core/context.ts +5 -6
  250. package/src/core/core-plugin.ts +3 -3
  251. package/src/core/event-tracker.ts +2 -2
  252. package/src/core/exporter.ts +3 -3
  253. package/src/core/index.ts +12 -9
  254. package/src/core/logger.ts +2 -2
  255. package/src/core/metadata.ts +23 -2
  256. package/src/core/meter.ts +3 -26
  257. package/src/core/numberish.ts +1 -1
  258. package/src/core/sui-plugin.ts +2 -2
  259. package/src/core/sui-processor.ts +1 -1
  260. package/src/error.ts +1 -1
  261. package/src/eth/account-processor-state.ts +1 -1
  262. package/src/eth/account-processor.ts +11 -11
  263. package/src/eth/base-processor-template.ts +5 -5
  264. package/src/eth/base-processor.ts +4 -4
  265. package/src/eth/binds.ts +3 -3
  266. package/src/eth/eth-plugin.ts +3 -3
  267. package/src/eth/generic-processor.ts +5 -5
  268. package/src/eth/index.ts +8 -6
  269. package/src/index.ts +4 -6
  270. package/src/target-ethers-sentio/{event-handler.ts → event-handler.cts} +1 -1
  271. package/src/target-ethers-sentio/{file.ts → file.cts} +10 -9
  272. package/src/target-ethers-sentio/{functions-handler.ts → functions-handler.cts} +3 -4
  273. package/src/target-ethers-sentio/{index.ts → index.cts} +4 -1
  274. package/src/target-ethers-sentio/tsconfig.json +1 -1
  275. package/src/target-ethers-sentio/{types.ts → types.cts} +0 -0
  276. package/src/target-ethers-sentio/{view-function.ts → view-function.cts} +1 -1
  277. package/src/testing/index.ts +3 -3
  278. package/src/testing/metric-utils.ts +2 -2
  279. package/src/testing/test-processor-server.ts +5 -5
  280. package/src/testing/test-provider.ts +1 -1
  281. package/src/tsup.config.ts +22 -0
  282. package/src/utils/conversion.ts +2 -2
  283. package/src/utils/dex-price.ts +4 -4
  284. package/src/utils/index.ts +4 -4
  285. package/src/utils/price.ts +1 -1
  286. package/src/utils/token.ts +6 -6
  287. package/lib/core/generic-processor.test.js.map +0 -1
  288. package/lib/target-ethers-sentio/event-handler.js.map +0 -1
  289. package/lib/target-ethers-sentio/file.js.map +0 -1
  290. package/lib/target-ethers-sentio/functions-handler.js.map +0 -1
  291. package/lib/target-ethers-sentio/index.js.map +0 -1
  292. package/lib/target-ethers-sentio/types.js.map +0 -1
  293. package/lib/target-ethers-sentio/view-function.js.map +0 -1
  294. package/lib/webpack.config.js +0 -50
  295. package/src/webpack.config.js +0 -50
@@ -1,20 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SuiBaseProcessor = exports.SuiProcessorState = exports.SuiBindOptions = void 0;
4
- const context_1 = require("./context");
5
- const runtime_1 = require("@sentio/runtime");
6
- class SuiBindOptions {
1
+ import { SuiContext } from './context.js';
2
+ import { ListStateStorage } from '@sentio/runtime';
3
+ export class SuiBindOptions {
7
4
  address;
8
5
  // network?: Networkish = 1
9
6
  // name?: string
10
7
  startBlock;
11
8
  }
12
- exports.SuiBindOptions = SuiBindOptions;
13
- class SuiProcessorState extends runtime_1.ListStateStorage {
9
+ export class SuiProcessorState extends ListStateStorage {
14
10
  static INSTANCE = new SuiProcessorState();
15
11
  }
16
- exports.SuiProcessorState = SuiProcessorState;
17
- class SuiBaseProcessor {
12
+ export class SuiBaseProcessor {
18
13
  transactionHanlder;
19
14
  address;
20
15
  config = { startSeqNumber: 0n };
@@ -30,7 +25,7 @@ class SuiBaseProcessor {
30
25
  return this;
31
26
  }
32
27
  handleTransaction(txn, slot) {
33
- const ctx = new context_1.SuiContext(this.address, slot);
28
+ const ctx = new SuiContext(this.address, slot);
34
29
  if (txn) {
35
30
  this.transactionHanlder(txn, ctx);
36
31
  }
@@ -45,5 +40,4 @@ class SuiBaseProcessor {
45
40
  return this;
46
41
  }
47
42
  }
48
- exports.SuiBaseProcessor = SuiBaseProcessor;
49
43
  //# sourceMappingURL=sui-processor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAEtC,6CAAkD;AAOlD,MAAa,cAAc;IACzB,OAAO,CAAQ;IACf,2BAA2B;IAC3B,gBAAgB;IAChB,UAAU,CAAkB;CAE7B;AAND,wCAMC;AAED,MAAa,iBAAkB,SAAQ,0BAAkC;IACvE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;AAD3C,8CAEC;AAED,MAAa,gBAAgB;IACpB,kBAAkB,CAA6C;IACtE,OAAO,CAAQ;IACf,MAAM,GAAmB,EAAE,cAAc,EAAE,EAAE,EAAE,CAAA;IAE/C,YAAY,IAAY,EAAE,OAAuB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SACnC;QACD,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3C,CAAC;IAEM,aAAa,CAAC,OAAoD;QACvE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,iBAAiB,CAAC,GAAQ,EAAE,IAAY;QAC7C,MAAM,GAAG,GAAG,IAAI,oBAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAE9C,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SAClC;QACD,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC/B,CAAC;IAEM,SAAS,CAAC,SAA0B;QACzC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;QAC9C,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAyB;QACvC,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AApCD,4CAoCC","sourcesContent":["import { SuiContext } from './context'\nimport { ProcessResult } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\n\ntype IndexConfigure = {\n startSeqNumber: bigint\n endSeqNumber?: bigint\n}\n\nexport class SuiBindOptions {\n address: string\n // network?: Networkish = 1\n // name?: string\n startBlock?: bigint | number\n // endBlock?: Long | number\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: 0n }\n\n constructor(name: string, options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n this.transactionHanlder = handler\n return this\n }\n\n public handleTransaction(txn: any, slot: bigint): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return ctx.getProcessResult()\n }\n\n public startSlot(startSlot: bigint | number) {\n this.config.startSeqNumber = BigInt(startSlot)\n return this\n }\n\n public endBlock(endBlock: bigint | number) {\n this.config.endSeqNumber = BigInt(endBlock)\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAOlD,MAAM,OAAO,cAAc;IACzB,OAAO,CAAQ;IACf,2BAA2B;IAC3B,gBAAgB;IAChB,UAAU,CAAkB;CAE7B;AAED,MAAM,OAAO,iBAAkB,SAAQ,gBAAkC;IACvE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;AAG3C,MAAM,OAAO,gBAAgB;IACpB,kBAAkB,CAA6C;IACtE,OAAO,CAAQ;IACf,MAAM,GAAmB,EAAE,cAAc,EAAE,EAAE,EAAE,CAAA;IAE/C,YAAY,IAAY,EAAE,OAAuB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SACnC;QACD,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3C,CAAC;IAEM,aAAa,CAAC,OAAoD;QACvE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,iBAAiB,CAAC,GAAQ,EAAE,IAAY;QAC7C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAE9C,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SAClC;QACD,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC/B,CAAC;IAEM,SAAS,CAAC,SAA0B;QACzC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;QAC9C,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAyB;QACvC,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { SuiContext } from './context.js'\nimport { ProcessResult } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\n\ntype IndexConfigure = {\n startSeqNumber: bigint\n endSeqNumber?: bigint\n}\n\nexport class SuiBindOptions {\n address: string\n // network?: Networkish = 1\n // name?: string\n startBlock?: bigint | number\n // endBlock?: Long | number\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: 0n }\n\n constructor(name: string, options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n this.transactionHanlder = handler\n return this\n }\n\n public handleTransaction(txn: any, slot: bigint): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return ctx.getProcessResult()\n }\n\n public startSlot(startSlot: bigint | number) {\n this.config.startSeqNumber = BigInt(startSlot)\n return this\n }\n\n public endBlock(endBlock: bigint | number) {\n this.config.endSeqNumber = BigInt(endBlock)\n return this\n }\n}\n"]}
package/lib/error.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContractContext } from './core/context';
1
+ import { ContractContext } from './core/context.js';
2
2
  export declare class EthersError extends Error {
3
3
  e: Error;
4
4
  constructor(message: string, e: Error);
package/lib/error.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformEtherError = exports.EthersError = void 0;
4
1
  // import { errors } from 'ethers/providers'
5
- class EthersError extends Error {
2
+ export class EthersError extends Error {
6
3
  e;
7
4
  constructor(message, e) {
8
5
  super(message);
@@ -12,8 +9,7 @@ class EthersError extends Error {
12
9
  return this.message + '\n' + this.stack?.toString();
13
10
  }
14
11
  }
15
- exports.EthersError = EthersError;
16
- function transformEtherError(e, ctx) {
12
+ export function transformEtherError(e, ctx) {
17
13
  let msg = '';
18
14
  // @ts-ignore expected error fields
19
15
  if (e.code === errors.CALL_EXCEPTION) {
@@ -39,5 +35,4 @@ function transformEtherError(e, ctx) {
39
35
  msg = 'ethers call error\n' + e.message + '\n' + e.stack?.toString();
40
36
  return new Error(msg);
41
37
  }
42
- exports.transformEtherError = transformEtherError;
43
38
  //# sourceMappingURL=error.js.map
package/lib/error.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAEA,4CAA4C;AAE5C,MAAa,WAAY,SAAQ,KAAK;IACpC,CAAC,CAAO;IAER,YAAY,OAAe,EAAE,CAAQ;QACnC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;IACtB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACrD,CAAC;CACF;AAXD,kCAWC;AAED,SAAgB,mBAAmB,CAAC,CAAQ,EAAE,GAA0C;IACtF,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,mCAAmC;IACnC,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,cAAc,EAAE;QACpC,mCAAmC;QACnC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;YACnB,IAAI,GAAG,EAAE;gBACP,GAAG;oBACD,sEAAsE;wBACtE,GAAG,CAAC,OAAO;wBACX,IAAI;wBACJ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACpB;iBAAM;gBACL,GAAG,GAAG,8DAA8D,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACzF;SACF;QACD,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;KAC/B;IAED,IAAI,CAAC,YAAY,WAAW,EAAE;QAC5B,OAAO,CAAC,CAAA;KACT;IAED,qCAAqC;IAErC,GAAG,GAAG,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACpE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC;AA3BD,kDA2BC","sourcesContent":["// Transform error in more readable format\nimport { ContractContext } from './core/context'\n// import { errors } from 'ethers/providers'\n\nexport class EthersError extends Error {\n e: Error\n\n constructor(message: string, e: Error) {\n super(message)\n this.stack = e.stack\n }\n\n toString() {\n return this.message + '\\n' + this.stack?.toString()\n }\n}\n\nexport function transformEtherError(e: Error, ctx: ContractContext<any, any> | undefined): Error {\n let msg = ''\n // @ts-ignore expected error fields\n if (e.code === errors.CALL_EXCEPTION) {\n // @ts-ignore expected error fields\n if (e.data === '0x') {\n if (ctx) {\n msg =\n \"jsonrpc eth_call return '0x' (likely contract not existed) at chain \" +\n ctx.chainId +\n ': ' +\n JSON.stringify(e)\n } else {\n msg = \"jsonrpc eth_call return '0x' (likely contract not existed): \" + JSON.stringify(e)\n }\n }\n return new EthersError(msg, e)\n }\n\n if (e instanceof EthersError) {\n return e\n }\n\n // TODO gracefully handle more errors\n\n msg = 'ethers call error\\n' + e.message + '\\n' + e.stack?.toString()\n return new Error(msg)\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAEA,4CAA4C;AAE5C,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,CAAC,CAAO;IAER,YAAY,OAAe,EAAE,CAAQ;QACnC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;IACtB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACrD,CAAC;CACF;AAED,MAAM,UAAU,mBAAmB,CAAC,CAAQ,EAAE,GAA0C;IACtF,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,mCAAmC;IACnC,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,cAAc,EAAE;QACpC,mCAAmC;QACnC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;YACnB,IAAI,GAAG,EAAE;gBACP,GAAG;oBACD,sEAAsE;wBACtE,GAAG,CAAC,OAAO;wBACX,IAAI;wBACJ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACpB;iBAAM;gBACL,GAAG,GAAG,8DAA8D,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACzF;SACF;QACD,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;KAC/B;IAED,IAAI,CAAC,YAAY,WAAW,EAAE;QAC5B,OAAO,CAAC,CAAA;KACT;IAED,qCAAqC;IAErC,GAAG,GAAG,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACpE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC","sourcesContent":["// Transform error in more readable format\nimport { ContractContext } from './core/context.js'\n// import { errors } from 'ethers/providers'\n\nexport class EthersError extends Error {\n e: Error\n\n constructor(message: string, e: Error) {\n super(message)\n this.stack = e.stack\n }\n\n toString() {\n return this.message + '\\n' + this.stack?.toString()\n }\n}\n\nexport function transformEtherError(e: Error, ctx: ContractContext<any, any> | undefined): Error {\n let msg = ''\n // @ts-ignore expected error fields\n if (e.code === errors.CALL_EXCEPTION) {\n // @ts-ignore expected error fields\n if (e.data === '0x') {\n if (ctx) {\n msg =\n \"jsonrpc eth_call return '0x' (likely contract not existed) at chain \" +\n ctx.chainId +\n ': ' +\n JSON.stringify(e)\n } else {\n msg = \"jsonrpc eth_call return '0x' (likely contract not existed): \" + JSON.stringify(e)\n }\n }\n return new EthersError(msg, e)\n }\n\n if (e instanceof EthersError) {\n return e\n }\n\n // TODO gracefully handle more errors\n\n msg = 'ethers call error\\n' + e.message + '\\n' + e.stack?.toString()\n return new Error(msg)\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { ListStateStorage } from '@sentio/runtime';
2
- import { AccountProcessor } from './account-processor';
2
+ import { AccountProcessor } from './account-processor.js';
3
3
  export declare class AccountProcessorState extends ListStateStorage<AccountProcessor> {
4
4
  static INSTANCE: AccountProcessorState;
5
5
  }
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountProcessorState = void 0;
4
- const runtime_1 = require("@sentio/runtime");
5
- class AccountProcessorState extends runtime_1.ListStateStorage {
1
+ import { ListStateStorage } from '@sentio/runtime';
2
+ export class AccountProcessorState extends ListStateStorage {
6
3
  static INSTANCE = new AccountProcessorState();
7
4
  }
8
- exports.AccountProcessorState = AccountProcessorState;
9
5
  //# sourceMappingURL=account-processor-state.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"account-processor-state.js","sourceRoot":"","sources":["../../src/eth/account-processor-state.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAGlD,MAAa,qBAAsB,SAAQ,0BAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA;;AAD/C,sDAEC","sourcesContent":["import { ListStateStorage } from '@sentio/runtime'\nimport { AccountProcessor } from './account-processor'\n\nexport class AccountProcessorState extends ListStateStorage<AccountProcessor> {\n static INSTANCE = new AccountProcessorState()\n}\n"]}
1
+ {"version":3,"file":"account-processor-state.js","sourceRoot":"","sources":["../../src/eth/account-processor-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD,MAAM,OAAO,qBAAsB,SAAQ,gBAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA","sourcesContent":["import { ListStateStorage } from '@sentio/runtime'\nimport { AccountProcessor } from './account-processor.js'\n\nexport class AccountProcessorState extends ListStateStorage<AccountProcessor> {\n static INSTANCE = new AccountProcessorState()\n}\n"]}
@@ -1,10 +1,10 @@
1
- import { EthFetchConfig } from '@sentio/sdk';
2
- import { AccountBindOptions } from '../core/bind-options';
3
- import { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20';
4
- import { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721';
5
- import { AccountContext } from '../core/context';
6
- import { PromiseOrVoid } from '../promise-or-void';
7
- import { AddressOrTypeEventFilter, EventsHandler } from './base-processor';
1
+ import { EthFetchConfig } from '@sentio/protos';
2
+ import { AccountBindOptions } from '../core/bind-options.js';
3
+ import { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20.js';
4
+ import { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721.js';
5
+ import { AccountContext } from '../core/context.js';
6
+ import { PromiseOrVoid } from '../promise-or-void.js';
7
+ import { AddressOrTypeEventFilter, EventsHandler } from './base-processor.js';
8
8
  import { LogDescription } from 'ethers';
9
9
  export declare class AccountProcessor {
10
10
  config: AccountBindOptions;
@@ -1,21 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountProcessor = void 0;
4
- const internal_1 = require("../builtin/internal");
5
- const sdk_1 = require("@sentio/sdk");
6
- const providers_1 = require("ethers/providers");
7
- const erc20_processor_1 = require("../builtin/internal/erc20_processor");
8
- const erc721_processor_1 = require("../builtin/internal/erc721_processor");
9
- const context_1 = require("../core/context");
10
- const account_processor_state_1 = require("./account-processor-state");
11
- const ERC20_INTERFACE = internal_1.ERC20__factory.createInterface();
12
- const ERC721_INTERFACE = internal_1.ERC721__factory.createInterface();
13
- class AccountProcessor {
1
+ import { ERC20__factory, ERC721__factory } from '../builtin/internal/index.js';
2
+ import { AddressType, EthFetchConfig, ProcessResult } from '@sentio/protos';
3
+ import { Network } from 'ethers/providers';
4
+ import { ERC20Processor } from '../builtin/internal/erc20_processor.js';
5
+ import { ERC721Processor } from '../builtin/internal/erc721_processor.js';
6
+ import { AccountContext } from '../core/context.js';
7
+ import { AccountProcessorState } from './account-processor-state.js';
8
+ const ERC20_INTERFACE = ERC20__factory.createInterface();
9
+ const ERC721_INTERFACE = ERC721__factory.createInterface();
10
+ export class AccountProcessor {
14
11
  config;
15
12
  eventHandlers = [];
16
13
  static bind(config) {
17
14
  const processor = new AccountProcessor(config);
18
- account_processor_state_1.AccountProcessorState.INSTANCE.addValue(processor);
15
+ AccountProcessorState.INSTANCE.addValue(processor);
19
16
  return processor;
20
17
  }
21
18
  constructor(config) {
@@ -28,7 +25,7 @@ class AccountProcessor {
28
25
  }
29
26
  }
30
27
  getChainId() {
31
- return Number(providers_1.Network.from(this.config.network || 1).chainId);
28
+ return Number(Network.from(this.config.network || 1).chainId);
32
29
  }
33
30
  /**
34
31
  * Register custom handler function to process erc20 transfer event to this account
@@ -37,7 +34,7 @@ class AccountProcessor {
37
34
  * @param fetchConfig
38
35
  */
39
36
  onERC20TransferIn(handler, tokensAddresses = [], fetchConfig) {
40
- return this.onERC20(handler, tokensAddresses, (address) => erc721_processor_1.ERC721Processor.filters.Transfer(null, this.config.address), fetchConfig);
37
+ return this.onERC20(handler, tokensAddresses, (address) => ERC721Processor.filters.Transfer(null, this.config.address), fetchConfig);
41
38
  }
42
39
  /**
43
40
  * Register custom handler function to process erc20 transfer event from this account
@@ -46,7 +43,7 @@ class AccountProcessor {
46
43
  * @param fetchConfig
47
44
  */
48
45
  onERC20TransferOut(handler, tokensAddresses = [], fetchConfig) {
49
- return this.onERC20(handler, tokensAddresses, (address) => erc20_processor_1.ERC20Processor.filters.Transfer(this.config.address), fetchConfig);
46
+ return this.onERC20(handler, tokensAddresses, (address) => ERC20Processor.filters.Transfer(this.config.address), fetchConfig);
50
47
  }
51
48
  /**
52
49
  * Register custom handler function to process erc20 mint for this account
@@ -55,10 +52,10 @@ class AccountProcessor {
55
52
  * @param fetchConfig
56
53
  */
57
54
  onERC20Minted(handler, tokensAddresses = [], fetchConfig) {
58
- return this.onERC20(handler, tokensAddresses, (address) => erc20_processor_1.ERC20Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address), fetchConfig);
55
+ return this.onERC20(handler, tokensAddresses, (address) => ERC20Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address), fetchConfig);
59
56
  }
60
57
  onERC20(handler, tokensAddresses = [], defaultFilter, fetchConfig) {
61
- return this.onERC(handler, tokensAddresses, defaultFilter, sdk_1.AddressType.ERC20, fetchConfig);
58
+ return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20, fetchConfig);
62
59
  }
63
60
  /**
64
61
  * Register custom handler function to process ERC721 transfer event to this account
@@ -67,7 +64,7 @@ class AccountProcessor {
67
64
  * @param fetchConfig
68
65
  */
69
66
  onERC721TransferIn(handler, collections, fetchConfig) {
70
- return this.onERC721(handler, collections, (address) => erc721_processor_1.ERC721Processor.filters.Transfer(null, this.config.address), fetchConfig);
67
+ return this.onERC721(handler, collections, (address) => ERC721Processor.filters.Transfer(null, this.config.address), fetchConfig);
71
68
  }
72
69
  /**
73
70
  * Register custom handler function to process ERC721 transfer event from this account
@@ -76,7 +73,7 @@ class AccountProcessor {
76
73
  * @param fetchConfig
77
74
  */
78
75
  onERC721TransferOut(handler, collections, fetchConfig) {
79
- return this.onERC721(handler, collections, (address) => erc721_processor_1.ERC721Processor.filters.Transfer(this.config.address), fetchConfig);
76
+ return this.onERC721(handler, collections, (address) => ERC721Processor.filters.Transfer(this.config.address), fetchConfig);
80
77
  }
81
78
  /**
82
79
  * Register custom handler function to process ERC721 mint for this account
@@ -85,10 +82,10 @@ class AccountProcessor {
85
82
  * @param fetchConfig
86
83
  */
87
84
  onERC721Minted(handler, collections = [], fetchConfig) {
88
- return this.onERC721(handler, collections, (address) => erc721_processor_1.ERC721Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address), fetchConfig);
85
+ return this.onERC721(handler, collections, (address) => ERC721Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address), fetchConfig);
89
86
  }
90
87
  onERC721(handler, collections, defaultFilter, fetchConfig) {
91
- return this.onERC(handler, collections, defaultFilter, sdk_1.AddressType.ERC721, fetchConfig);
88
+ return this.onERC(handler, collections, defaultFilter, AddressType.ERC721, fetchConfig);
92
89
  }
93
90
  onERC(handler, contractAddresses, defaultFilter, addressType, fetchConfig) {
94
91
  const filters = [];
@@ -132,20 +129,19 @@ class AccountProcessor {
132
129
  const config = this.config;
133
130
  this.eventHandlers.push({
134
131
  filters: _filters,
135
- fetchConfig: fetchConfig || sdk_1.EthFetchConfig.fromPartial({}),
132
+ fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
136
133
  handler: async function (data) {
137
134
  const log = data.log;
138
- const ctx = new context_1.AccountContext(chainId, config.address, data.timestamp, data.block, log, undefined, data.transaction, data.transactionReceipt);
135
+ const ctx = new AccountContext(chainId, config.address, data.timestamp, data.block, log, undefined, data.transaction, data.transactionReceipt);
139
136
  const parsed = ERC20_INTERFACE.parseLog(log);
140
137
  if (parsed) {
141
138
  await handler(parsed, ctx);
142
139
  return ctx.getProcessResult();
143
140
  }
144
- return sdk_1.ProcessResult.fromPartial({});
141
+ return ProcessResult.fromPartial({});
145
142
  },
146
143
  });
147
144
  return this;
148
145
  }
149
146
  }
150
- exports.AccountProcessor = AccountProcessor;
151
147
  //# sourceMappingURL=account-processor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"account-processor.js","sourceRoot":"","sources":["../../src/eth/account-processor.ts"],"names":[],"mappings":";;;AAAA,kDAAqE;AACrE,qCAAuF;AAGvF,gDAAqD;AAKrD,yEAAoE;AACpE,2EAAsE;AAEtE,6CAAgD;AAIhD,uEAAiE;AAEjE,MAAM,eAAe,GAAG,yBAAc,CAAC,eAAe,EAAE,CAAA;AACxD,MAAM,gBAAgB,GAAG,0BAAe,CAAC,eAAe,EAAE,CAAA;AAE1D,MAAa,gBAAgB;IAC3B,MAAM,CAAoB;IAC1B,aAAa,GAAoB,EAAE,CAAA;IAEnC,MAAM,CAAC,IAAI,CAAC,MAA0B;QACpC,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC9C,+CAAqB,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAClD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,YAAsB,MAA0B;QAC9C,IAAI,CAAC,MAAM,GAAG,M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,mEAAmE;QACnE,IAAI;QAEJ,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QAE1B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,QAAQ;YACjB,WAAW,EAAE,WAAW,IAAI,oBAAc,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1D,OAAO,EAAE,KAAK,WAAW,IAAI;gBAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAA8C,CAAA;gBAC/D,MAAM,GAAG,GAAG,IAAI,wBAAc,CAC5B,OAAO,EACP,MAAM,CAAC,OAAO,EACd,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,KAAc,EACnB,GAAuB,EACvB,SAAS,EACT,IAAI,CAAC,WAA0B,EAC/B,IAAI,CAAC,kBAAwC,CAC9C,CAAA;gBACD,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;gBAC5C,IAAI,MAAM,EAAE;oBACV,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;oBAC1B,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;iBAC9B;gBACD,OAAO,mBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;YACtC,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA/OD,4CA+OC","sourcesContent":["import { ERC20__factory, ERC721__factory } from '../builtin/internal'\nimport { AddressType, DummyProvider, EthFetchConfig, ProcessResult } from '@sentio/sdk'\nimport { AccountBindOptions } from '../core/bind-options'\n\nimport { Network, LogParams } from 'ethers/providers'\n\nimport { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20'\nimport { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721'\n\nimport { ERC20Processor } from '../builtin/internal/erc20_processor'\nimport { ERC721Processor } from '../builtin/internal/erc721_processor'\n\nimport { AccountContext } from '../core/context'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { AddressOrTypeEventFilter, EventsHandler } from './base-processor'\nimport { Transaction, Block, TransactionReceipt, LogDescription } from 'ethers'\nimport { AccountProcessorState } from './account-processor-state'\n\nconst ERC20_INTERFACE = ERC20__factory.createInterface()\nconst ERC721_INTERFACE = ERC721__factory.createInterface()\n\nexport class AccountProcessor {\n config: AccountBindOptions\n eventHandlers: EventsHandler[] = []\n\n static bind(config: AccountBindOptions): AccountProcessor {\n const processor = new AccountProcessor(config)\n AccountProcessorState.INSTANCE.addValue(processor)\n return processor\n }\n\n protected constructor(config: AccountBindOptions) {\n this.config = config\n if (typeof this.config.network === 'string') {\n const asInt = parseInt(this.config.network)\n if (Number.isFinite(asInt)) {\n this.config.network = asInt\n }\n }\n }\n\n public getChainId(): number {\n return Number(Network.from(this.config.network || 1).chainId)\n }\n\n /**\n * Register custom handler function to process erc20 transfer event to this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20TransferIn(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) => ERC721Processor.filters.Transfer(null, this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process erc20 transfer event from this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20TransferOut(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) => ERC20Processor.filters.Transfer(this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process erc20 mint for this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20Minted(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) =>\n ERC20Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),\n fetchConfig\n )\n }\n\n private onERC20(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20, fetchConfig)\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event to this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721TransferIn(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) => ERC721Processor.filters.Transfer(null, this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event from this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721TransferOut(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) => ERC721Processor.filters.Transfer(this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process ERC721 mint for this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721Minted(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) =>\n ERC721Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),\n fetchConfig\n )\n }\n\n private onERC721(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC(handler, collections, defaultFilter, AddressType.ERC721, fetchConfig)\n }\n\n private onERC(\n handler: (event: any, ctx: AccountContext) => PromiseOrVoid,\n contractAddresses: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n addressType: AddressType,\n fetchConfig?: EthFetchConfig\n ) {\n const filters = []\n for (const token of contractAddresses) {\n const filter = defaultFilter(this.config.address)\n filter.address = token\n filters.push(filter)\n }\n if (!filters.length) {\n const filter = defaultFilter(this.config.address)\n filter.address = undefined\n filter.addressType = addressType\n filters.push(filter)\n }\n return this.onEvent(handler, filters, fetchConfig)\n }\n\n protected onEvent(\n handler: (event: LogDescription, ctx: AccountContext) => PromiseOrVoid,\n filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[],\n fetchConfig?: EthFetchConfig\n ) {\n const chainId = this.getChainId()\n\n let _filters: AddressOrTypeEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // let hasVaildConfig = false\n // for (const filter of _filters) {\n // if (filter.address) {\n // hasVaildConfig = true\n // break\n // }\n // if (filter.topics && filter.topics.length) {\n // hasVaildConfig = true\n // break\n // }\n // }\n //\n // if (!hasVaildConfig) {\n // throw Error('no valid config has been found for this account')\n // }\n\n const config = this.config\n\n this.eventHandlers.push({\n filters: _filters,\n fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),\n handler: async function (data) {\n const log = data.log as { topics: Array<string>; data: string }\n const ctx = new AccountContext(\n chainId,\n config.address,\n data.timestamp,\n data.block as Block,\n log as any as LogParams,\n undefined,\n data.transaction as Transaction,\n data.transactionReceipt as TransactionReceipt\n )\n const parsed = ERC20_INTERFACE.parseLog(log)\n if (parsed) {\n await handler(parsed, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPart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A;gBAC/D,MAAM,GAAG,GAAG,IAAI,cAAc,CAC5B,OAAO,EACP,MAAM,CAAC,OAAO,EACd,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,KAAc,EACnB,GAAuB,EACvB,SAAS,EACT,IAAI,CAAC,WAA0B,EAC/B,IAAI,CAAC,kBAAwC,CAC9C,CAAA;gBACD,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;gBAC5C,IAAI,MAAM,EAAE;oBACV,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;oBAC1B,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;iBAC9B;gBACD,OAAO,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;YACtC,CAAC;SACF,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { ERC20__factory, ERC721__factory } from '../builtin/internal/index.js'\nimport { AddressType, EthFetchConfig, ProcessResult } from '@sentio/protos'\nimport { AccountBindOptions } from '../core/bind-options.js'\n\nimport { Network, LogParams } from 'ethers/providers'\n\nimport { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20.js'\nimport { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721.js'\n\nimport { ERC20Processor } from '../builtin/internal/erc20_processor.js'\nimport { ERC721Processor } from '../builtin/internal/erc721_processor.js'\n\nimport { AccountContext } from '../core/context.js'\nimport { PromiseOrVoid } from '../promise-or-void.js'\nimport { AddressOrTypeEventFilter, EventsHandler } from './base-processor.js'\nimport { Transaction, Block, TransactionReceipt, LogDescription } from 'ethers'\nimport { AccountProcessorState } from './account-processor-state.js'\n\nconst ERC20_INTERFACE = ERC20__factory.createInterface()\nconst ERC721_INTERFACE = ERC721__factory.createInterface()\n\nexport class AccountProcessor {\n config: AccountBindOptions\n eventHandlers: EventsHandler[] = []\n\n static bind(config: AccountBindOptions): AccountProcessor {\n const processor = new AccountProcessor(config)\n AccountProcessorState.INSTANCE.addValue(processor)\n return processor\n }\n\n protected constructor(config: AccountBindOptions) {\n this.config = config\n if (typeof this.config.network === 'string') {\n const asInt = parseInt(this.config.network)\n if (Number.isFinite(asInt)) {\n this.config.network = asInt\n }\n }\n }\n\n public getChainId(): number {\n return Number(Network.from(this.config.network || 1).chainId)\n }\n\n /**\n * Register custom handler function to process erc20 transfer event to this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20TransferIn(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) => ERC721Processor.filters.Transfer(null, this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process erc20 transfer event from this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20TransferOut(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) => ERC20Processor.filters.Transfer(this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process erc20 mint for this account\n * @param handler custom handler function\n * @param tokensAddresses all the erc20 token address to watch\n * @param fetchConfig\n */\n onERC20Minted(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC20(\n handler,\n tokensAddresses,\n (address: string) =>\n ERC20Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),\n fetchConfig\n )\n }\n\n private onERC20(\n handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n tokensAddresses: string[] = [],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20, fetchConfig)\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event to this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721TransferIn(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) => ERC721Processor.filters.Transfer(null, this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process ERC721 transfer event from this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721TransferOut(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) => ERC721Processor.filters.Transfer(this.config.address),\n fetchConfig\n )\n }\n\n /**\n * Register custom handler function to process ERC721 mint for this account\n * @param handler custom handler function\n * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721\n * @param fetchConfig\n */\n onERC721Minted(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[] = [],\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC721(\n handler,\n collections,\n (address: string) =>\n ERC721Processor.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address),\n fetchConfig\n )\n }\n\n private onERC721(\n handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,\n collections: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onERC(handler, collections, defaultFilter, AddressType.ERC721, fetchConfig)\n }\n\n private onERC(\n handler: (event: any, ctx: AccountContext) => PromiseOrVoid,\n contractAddresses: string[],\n defaultFilter: (address: string) => AddressOrTypeEventFilter,\n addressType: AddressType,\n fetchConfig?: EthFetchConfig\n ) {\n const filters = []\n for (const token of contractAddresses) {\n const filter = defaultFilter(this.config.address)\n filter.address = token\n filters.push(filter)\n }\n if (!filters.length) {\n const filter = defaultFilter(this.config.address)\n filter.address = undefined\n filter.addressType = addressType\n filters.push(filter)\n }\n return this.onEvent(handler, filters, fetchConfig)\n }\n\n protected onEvent(\n handler: (event: LogDescription, ctx: AccountContext) => PromiseOrVoid,\n filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[],\n fetchConfig?: EthFetchConfig\n ) {\n const chainId = this.getChainId()\n\n let _filters: AddressOrTypeEventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // let hasVaildConfig = false\n // for (const filter of _filters) {\n // if (filter.address) {\n // hasVaildConfig = true\n // break\n // }\n // if (filter.topics && filter.topics.length) {\n // hasVaildConfig = true\n // break\n // }\n // }\n //\n // if (!hasVaildConfig) {\n // throw Error('no valid config has been found for this account')\n // }\n\n const config = this.config\n\n this.eventHandlers.push({\n filters: _filters,\n fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),\n handler: async function (data) {\n const log = data.log as { topics: Array<string>; data: string }\n const ctx = new AccountContext(\n chainId,\n config.address,\n data.timestamp,\n data.block as Block,\n log as any as LogParams,\n undefined,\n data.transaction as Transaction,\n data.transactionReceipt as TransactionReceipt\n )\n const parsed = ERC20_INTERFACE.parseLog(log)\n if (parsed) {\n await handler(parsed, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n\n return this\n }\n}\n"]}
@@ -1,10 +1,10 @@
1
- import { BoundContractView, ContractContext, ContractView } from '../core/context';
1
+ import { BoundContractView, ContractContext, ContractView } from '../core/context.js';
2
2
  import { BaseContract, Block, LogDescription } from 'ethers';
3
- import { BaseProcessor } from './base-processor';
4
- import { BindOptions } from '../core/bind-options';
3
+ import { BaseProcessor } from './base-processor.js';
4
+ import { BindOptions } from '../core/bind-options.js';
5
5
  import { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos';
6
- import { PromiseOrVoid } from '../promise-or-void';
7
- import { Trace } from './trace';
6
+ import { PromiseOrVoid } from '../promise-or-void.js';
7
+ import { Trace } from './trace.js';
8
8
  import { ListStateStorage } from '@sentio/runtime';
9
9
  import { DeferredTopicFilter } from 'ethers/contract';
10
10
  export declare class ProcessorTemplateProcessorState extends ListStateStorage<BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>> {
@@ -1,18 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseProcessorTemplate = exports.TemplateInstanceState = exports.ProcessorTemplateProcessorState = void 0;
4
- const bind_options_1 = require("../core/bind-options");
5
- const runtime_1 = require("@sentio/runtime");
6
- const providers_1 = require("ethers/providers");
7
- class ProcessorTemplateProcessorState extends runtime_1.ListStateStorage {
1
+ import { getOptionsSignature } from '../core/bind-options.js';
2
+ import { ListStateStorage } from '@sentio/runtime';
3
+ import { Network } from 'ethers/providers';
4
+ export class ProcessorTemplateProcessorState extends ListStateStorage {
8
5
  static INSTANCE = new ProcessorTemplateProcessorState();
9
6
  }
10
- exports.ProcessorTemplateProcessorState = ProcessorTemplateProcessorState;
11
- class TemplateInstanceState extends runtime_1.ListStateStorage {
7
+ export class TemplateInstanceState extends ListStateStorage {
12
8
  static INSTANCE = new TemplateInstanceState();
13
9
  }
14
- exports.TemplateInstanceState = TemplateInstanceState;
15
- class BaseProcessorTemplate {
10
+ export class BaseProcessorTemplate {
16
11
  id;
17
12
  binds = new Set();
18
13
  blockHandlers = [];
@@ -23,7 +18,7 @@ class BaseProcessorTemplate {
23
18
  ProcessorTemplateProcessorState.INSTANCE.addValue(this);
24
19
  }
25
20
  bind(options) {
26
- const sig = (0, bind_options_1.getOptionsSignature)(options);
21
+ const sig = getOptionsSignature(options);
27
22
  if (this.binds.has(sig)) {
28
23
  return;
29
24
  }
@@ -43,7 +38,7 @@ class BaseProcessorTemplate {
43
38
  contract: {
44
39
  address: options.address,
45
40
  name: options.name || '',
46
- chainId: options.network ? providers_1.Network.from(options.network).chainId.toString() : '1',
41
+ chainId: options.network ? Network.from(options.network).chainId.toString() : '1',
47
42
  abi: '',
48
43
  },
49
44
  startBlock: 0n,
@@ -84,5 +79,4 @@ class BaseProcessorTemplate {
84
79
  return this;
85
80
  }
86
81
  }
87
- exports.BaseProcessorTemplate = BaseProcessorTemplate;
88
82
  //# sourceMappingURL=base-processor-template.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":";;;AAGA,uDAAuE;AAIvE,6CAAkD;AAClD,gDAAkE;AAGlE,MAAa,+BAAgC,SAAQ,0BAEpD;IACC,MAAM,CAAC,QAAQ,GAAG,IAAI,+BAA+B,EAAE,CAAA;;AAHzD,0EAIC;AAED,MAAa,qBAAsB,SAAQ,0BAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA;;AAD/C,sDAEC;AAED,MAAsB,qBAAqB;IAIzC,EAAE,CAAQ;IACV,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IACzB,aAAa,GAIP,EAAE,CAAA;IACR,aAAa,GAIP,EAAE,CAAA;IACR,aAAa,GAIP,EAAE,CAAA;IAER;QACE,IAAI,CAAC,EAAE,GAAG,+BAA+B,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,CAAA;QACrE,+BAA+B,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC;IAEM,IAAI,CAAC,OAAoB;QAC9B,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,OAAO,CAAC,CAAA;QACxC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACvB,OAAM;SACP;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEnB,MAAM,SAA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,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACjD,OAAO,SAAS,CAAA;IAClB,CAAC;IAEM,OAAO,CACZ,OAAsG,EACtG,MAAmD,EACnD,WAA4B;QAE5B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,OAAO;YAChB,MAAM,EAAE,MAAM;YACd,WAAW,EAAE,WAAW;SACzB,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,eAAe,CACpB,OAA6F,EAC7F,aAAa,GAAG,IAAI,EACpB,qBAAqB,GAAG,IAAI;QAE5B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE;YACzC,cAAc,EAAE,aAAa;YAC7B,gBAAgB,EAAE,qBAAqB;SACxC,CAAC,CAAA;IACJ,CAAC;IAEM,cAAc,CACnB,OAA6F,EAC7F,qBAAqB,GAAG,EAAE,EAC1B,qBAAqB,GAAG,GAAG;QAE3B,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,EAAE,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,EAClF,SAAS,CACV,CAAA;IACH,CAAC;IAEM,UAAU,CACf,OAA6F,EAC7F,YAAwC,EACxC,aAAyC;QAEzC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC,CAAA;QACvG,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CACZ,SAAiB,EACjB,OAA6F;QAE7F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC;CAGF;AAzHD,sDAyHC","sourcesContent":["import { BoundContractView, ContractContext, ContractView } from '../core/context'\nimport { BaseContract, ContractEvent, Block, LogDescription } from 'ethers'\nimport { AddressOrTypeEventFilter, BaseProcessor } from './base-processor'\nimport { BindOptions, getOptionsSignature } from '../core/bind-options'\nimport { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { EventFilter, LogParams, Network } from 'ethers/providers'\nimport { DeferredTopicFilter } from 'ethers/contract'\n\nexport class ProcessorTemplateProcessorState extends ListStateStorage<\n BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>\n> {\n static INSTANCE = new ProcessorTemplateProcessorState()\n}\n\nexport class TemplateInstanceState extends ListStateStorage<TemplateInstance> {\n static INSTANCE = new TemplateInstanceState()\n}\n\nexport abstract class BaseProcessorTemplate<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n id: number\n binds = new Set<string>()\n blockHandlers: {\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n }[] = []\n traceHandlers: {\n signature: string\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n fetchConfig?: EthFetchConfig\n }[] = []\n eventHandlers: {\n handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n filter: DeferredTopicFilter | DeferredTopicFilter[]\n fetchConfig?: EthFetchConfig\n }[] = []\n\n constructor() {\n this.id = ProcessorTemplateProcessorState.INSTANCE.getValues().length\n ProcessorTemplateProcessorState.INSTANCE.addValue(this)\n }\n\n public bind(options: BindOptions) {\n const sig = getOptionsSignature(options)\n if (this.binds.has(sig)) {\n return\n }\n this.binds.add(sig)\n\n const processor = this.bindInternal(options)\n\n for (const eh of this.eventHandlers) {\n processor.onEvent(eh.handler, eh.filter, eh.fetchConfig)\n }\n for (const th of this.traceHandlers) {\n processor.onTrace(th.signature, th.handler, th.fetchConfig)\n }\n for (const bh of this.blockHandlers) {\n processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: options.network ? Network.from(options.network).chainId.toString() : '1',\n abi: '',\n },\n startBlock: 0n,\n endBlock: 0n,\n }\n if (options.startBlock) {\n instance.startBlock = BigInt(options.startBlock)\n }\n if (options.endBlock) {\n instance.endBlock = BigInt(options.endBlock)\n }\n TemplateInstanceState.INSTANCE.addValue(instance)\n return processor\n }\n\n public onEvent(\n handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: EthFetchConfig\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n fetchConfig: fetchConfig,\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000,\n backfillBlockInterval = 4000\n ) {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillBlockInterval = 240\n ) {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },\n undefined\n )\n }\n\n public onInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ) {\n this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval })\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n this.traceHandlers.push({ signature, handler })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract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,EAAE,OAAO;YAChB,MAAM,EAAE,MAAM;YACd,WAAW,EAAE,WAAW;SACzB,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,eAAe,CACpB,OAA6F,EAC7F,aAAa,GAAG,IAAI,EACpB,qBAAqB,GAAG,IAAI;QAE5B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE;YACzC,cAAc,EAAE,aAAa;YAC7B,gBAAgB,EAAE,qBAAqB;SACxC,CAAC,CAAA;IACJ,CAAC;IAEM,cAAc,CACnB,OAA6F,EAC7F,qBAAqB,GAAG,EAAE,EAC1B,qBAAqB,GAAG,GAAG;QAE3B,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,EAAE,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,EAClF,SAAS,CACV,CAAA;IACH,CAAC;IAEM,UAAU,CACf,OAA6F,EAC7F,YAAwC,EACxC,aAAyC;QAEzC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC,CAAA;QACvG,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CACZ,SAAiB,EACjB,OAA6F;QAE7F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC;CAGF","sourcesContent":["import { BoundContractView, ContractContext, ContractView } from '../core/context.js'\nimport { BaseContract, ContractEvent, Block, LogDescription } from 'ethers'\nimport { AddressOrTypeEventFilter, BaseProcessor } from './base-processor.js'\nimport { BindOptions, getOptionsSignature } from '../core/bind-options.js'\nimport { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos'\nimport { PromiseOrVoid } from '../promise-or-void.js'\nimport { Trace } from './trace.js'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { EventFilter, LogParams, Network } from 'ethers/providers'\nimport { DeferredTopicFilter } from 'ethers/contract'\n\nexport class ProcessorTemplateProcessorState extends ListStateStorage<\n BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>\n> {\n static INSTANCE = new ProcessorTemplateProcessorState()\n}\n\nexport class TemplateInstanceState extends ListStateStorage<TemplateInstance> {\n static INSTANCE = new TemplateInstanceState()\n}\n\nexport abstract class BaseProcessorTemplate<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n id: number\n binds = new Set<string>()\n blockHandlers: {\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n }[] = []\n traceHandlers: {\n signature: string\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n fetchConfig?: EthFetchConfig\n }[] = []\n eventHandlers: {\n handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n filter: DeferredTopicFilter | DeferredTopicFilter[]\n fetchConfig?: EthFetchConfig\n }[] = []\n\n constructor() {\n this.id = ProcessorTemplateProcessorState.INSTANCE.getValues().length\n ProcessorTemplateProcessorState.INSTANCE.addValue(this)\n }\n\n public bind(options: BindOptions) {\n const sig = getOptionsSignature(options)\n if (this.binds.has(sig)) {\n return\n }\n this.binds.add(sig)\n\n const processor = this.bindInternal(options)\n\n for (const eh of this.eventHandlers) {\n processor.onEvent(eh.handler, eh.filter, eh.fetchConfig)\n }\n for (const th of this.traceHandlers) {\n processor.onTrace(th.signature, th.handler, th.fetchConfig)\n }\n for (const bh of this.blockHandlers) {\n processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: options.network ? Network.from(options.network).chainId.toString() : '1',\n abi: '',\n },\n startBlock: 0n,\n endBlock: 0n,\n }\n if (options.startBlock) {\n instance.startBlock = BigInt(options.startBlock)\n }\n if (options.endBlock) {\n instance.endBlock = BigInt(options.endBlock)\n }\n TemplateInstanceState.INSTANCE.addValue(instance)\n return processor\n }\n\n public onEvent(\n handler: (event: LogDescription, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: EthFetchConfig\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n fetchConfig: fetchConfig,\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000,\n backfillBlockInterval = 4000\n ) {\n return this.onInterval(handler, undefined, {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n })\n }\n\n public onTimeInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillBlockInterval = 240\n ) {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },\n undefined\n )\n }\n\n public onInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined\n ) {\n this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval })\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n this.traceHandlers.push({ signature, handler })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import { Block, BaseContract, DeferredTopicFilter, LogDescription } from 'ethers';
2
- import { BoundContractView, ContractContext, ContractView } from '../core/context';
2
+ import { BoundContractView, ContractContext, ContractView } from '../core/context.js';
3
3
  import { AddressType, Data_EthBlock, Data_EthLog, Data_EthTrace, EthFetchConfig, HandleInterval, ProcessResult } from '@sentio/protos';
4
- import { BindInternalOptions, BindOptions } from '../core/bind-options';
5
- import { PromiseOrVoid } from '../promise-or-void';
6
- import { Trace } from './trace';
4
+ import { BindInternalOptions, BindOptions } from '../core/bind-options.js';
5
+ import { PromiseOrVoid } from '../promise-or-void.js';
6
+ import { Trace } from './trace.js';
7
7
  export interface AddressOrTypeEventFilter extends DeferredTopicFilter {
8
8
  addressType?: AddressType;
9
9
  address?: string;
@@ -1,29 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseProcessor = exports.BlockHandlder = exports.TraceHandler = exports.EventsHandler = void 0;
4
- const providers_1 = require("ethers/providers");
5
- const context_1 = require("../core/context");
6
- const protos_1 = require("@sentio/protos");
7
- const nice_grpc_1 = require("nice-grpc");
8
- class EventsHandler {
1
+ import { Network } from 'ethers/providers';
2
+ import { ContractContext } from '../core/context.js';
3
+ import { EthFetchConfig, ProcessResult, } from '@sentio/protos';
4
+ import { ServerError, Status } from 'nice-grpc';
5
+ export class EventsHandler {
9
6
  filters;
10
7
  handler;
11
8
  fetchConfig;
12
9
  }
13
- exports.EventsHandler = EventsHandler;
14
- class TraceHandler {
10
+ export class TraceHandler {
15
11
  signature;
16
12
  handler;
17
13
  fetchConfig;
18
14
  }
19
- exports.TraceHandler = TraceHandler;
20
- class BlockHandlder {
15
+ export class BlockHandlder {
21
16
  blockInterval;
22
17
  timeIntervalInMinutes;
23
18
  handler;
24
19
  }
25
- exports.BlockHandlder = BlockHandlder;
26
- class BaseProcessor {
20
+ export class BaseProcessor {
27
21
  blockHandlers = [];
28
22
  eventHandlers = [];
29
23
  traceHandlers = [];
@@ -49,7 +43,7 @@ class BaseProcessor {
49
43
  }
50
44
  }
51
45
  getChainId() {
52
- return Number(providers_1.Network.from(this.config.network).chainId);
46
+ return Number(Network.from(this.config.network).chainId);
53
47
  }
54
48
  onEvent(handler, filter, fetchConfig) {
55
49
  const chainId = this.getChainId();
@@ -64,21 +58,21 @@ class BaseProcessor {
64
58
  const processor = this;
65
59
  this.eventHandlers.push({
66
60
  filters: _filters,
67
- fetchConfig: fetchConfig || protos_1.EthFetchConfig.fromPartial({}),
61
+ fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
68
62
  handler: async function (data) {
69
63
  if (!data.log) {
70
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Log is empty');
64
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Log is empty');
71
65
  }
72
66
  const log = data.log;
73
67
  const contractView = processor.CreateBoundContractView();
74
- const ctx = new context_1.ContractContext(contractName, contractView, chainId, data.timestamp, data.block, log, undefined, data.transaction, data.transactionReceipt);
68
+ const ctx = new ContractContext(contractName, contractView, chainId, data.timestamp, data.block, log, undefined, data.transaction, data.transactionReceipt);
75
69
  const logParam = log;
76
70
  const parsed = contractView.rawContract.interface.parseLog(logParam);
77
71
  if (parsed) {
78
72
  await handler(parsed, ctx);
79
73
  return ctx.getProcessResult();
80
74
  }
81
- return protos_1.ProcessResult.fromPartial({});
75
+ return ProcessResult.fromPartial({});
82
76
  },
83
77
  });
84
78
  return this;
@@ -99,11 +93,11 @@ class BaseProcessor {
99
93
  this.blockHandlers.push({
100
94
  handler: async function (data) {
101
95
  if (!data.block) {
102
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Block is empty');
96
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Block is empty');
103
97
  }
104
98
  const block = data.block;
105
99
  const contractView = processor.CreateBoundContractView();
106
- const ctx = new context_1.ContractContext(contractName, contractView, chainId, new Date(block.timestamp * 1000), block, undefined, undefined);
100
+ const ctx = new ContractContext(contractName, contractView, chainId, new Date(block.timestamp * 1000), block, undefined, undefined);
107
101
  await handler(block, ctx);
108
102
  return ctx.getProcessResult();
109
103
  },
@@ -131,21 +125,21 @@ class BaseProcessor {
131
125
  const processor = this;
132
126
  this.traceHandlers.push({
133
127
  signature,
134
- fetchConfig: fetchConfig || protos_1.EthFetchConfig.fromPartial({}),
128
+ fetchConfig: fetchConfig || EthFetchConfig.fromPartial({}),
135
129
  handler: async function (data) {
136
130
  const contractView = processor.CreateBoundContractView();
137
131
  const contractInterface = contractView.rawContract.interface;
138
132
  const fragment = contractInterface.getFunction(signature);
139
133
  if (!data.trace || !fragment) {
140
- throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'trace is null');
134
+ throw new ServerError(Status.INVALID_ARGUMENT, 'trace is null');
141
135
  }
142
136
  const trace = data.trace;
143
137
  if (!trace.action.input) {
144
- return protos_1.ProcessResult.fromPartial({});
138
+ return ProcessResult.fromPartial({});
145
139
  }
146
140
  const traceData = '0x' + trace.action.input.slice(10);
147
141
  trace.args = contractInterface.getAbiCoder().decode(fragment.inputs, traceData);
148
- const ctx = new context_1.ContractContext(contractName, contractView, chainId, data.timestamp, data.block, undefined, trace, data.transaction, data.transactionReceipt);
142
+ const ctx = new ContractContext(contractName, contractView, chainId, data.timestamp, data.block, undefined, trace, data.transaction, data.transactionReceipt);
149
143
  await handler(trace, ctx);
150
144
  return ctx.getProcessResult();
151
145
  },
@@ -153,5 +147,4 @@ class BaseProcessor {
153
147
  return this;
154
148
  }
155
149
  }
156
- exports.BaseProcessor = BaseProcessor;
157
150
  //# sourceMappingURL=base-processor.js.map