@sentio/sdk 1.0.0-development → 1.0.0-rc.3

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 (609) hide show
  1. package/LICENSE +55 -0
  2. package/lib/aptos/api.d.ts +2 -0
  3. package/lib/aptos/api.js +14 -0
  4. package/lib/aptos/api.js.map +1 -0
  5. package/lib/aptos/aptos-plugin.d.ts +14 -0
  6. package/lib/aptos/aptos-plugin.js +190 -0
  7. package/lib/aptos/aptos-plugin.js.map +1 -0
  8. package/lib/aptos/aptos-processor.d.ts +75 -0
  9. package/lib/aptos/aptos-processor.js +193 -0
  10. package/lib/aptos/aptos-processor.js.map +1 -0
  11. package/lib/aptos/context.d.ts +22 -0
  12. package/lib/aptos/context.js +69 -0
  13. package/lib/aptos/context.js.map +1 -0
  14. package/lib/aptos/index.d.ts +9 -0
  15. package/lib/aptos/index.js +34 -0
  16. package/lib/aptos/index.js.map +1 -0
  17. package/lib/aptos/models.d.ts +23 -0
  18. package/lib/aptos/models.js +3 -0
  19. package/lib/aptos/models.js.map +1 -0
  20. package/lib/aptos/network.d.ts +14 -0
  21. package/lib/aptos/network.js +46 -0
  22. package/lib/aptos/network.js.map +1 -0
  23. package/lib/aptos/runtime.d.ts +2 -0
  24. package/lib/aptos/runtime.js +16 -0
  25. package/lib/aptos/runtime.js.map +1 -0
  26. package/lib/aptos/type-registry.d.ts +21 -0
  27. package/lib/aptos/type-registry.js +156 -0
  28. package/lib/aptos/type-registry.js.map +1 -0
  29. package/lib/aptos/types.d.ts +9 -0
  30. package/lib/aptos/types.js +135 -0
  31. package/lib/aptos/types.js.map +1 -0
  32. package/{dist/numberish.test.d.ts → lib/aptos/types.test.d.ts} +0 -0
  33. package/lib/aptos/types.test.js.map +1 -0
  34. package/lib/aptos/utils.d.ts +7 -0
  35. package/lib/aptos/utils.js +27 -0
  36. package/lib/aptos/utils.js.map +1 -0
  37. package/lib/aptos-codegen/codegen.d.ts +23 -0
  38. package/lib/aptos-codegen/codegen.js +364 -0
  39. package/lib/aptos-codegen/codegen.js.map +1 -0
  40. package/lib/aptos-codegen/typegen.d.ts +17 -0
  41. package/lib/aptos-codegen/typegen.js +142 -0
  42. package/lib/aptos-codegen/typegen.js.map +1 -0
  43. package/lib/binds.d.ts +12 -0
  44. package/lib/binds.js +38 -0
  45. package/lib/binds.js.map +1 -0
  46. package/lib/builtin/aptos/0x1.d.ts +1913 -0
  47. package/lib/builtin/aptos/0x1.js +2748 -0
  48. package/lib/builtin/aptos/0x1.js.map +1 -0
  49. package/lib/builtin/aptos/0x3.d.ts +482 -0
  50. package/lib/builtin/aptos/0x3.js +526 -0
  51. package/lib/builtin/aptos/0x3.js.map +1 -0
  52. package/lib/builtin/aptos/index.d.ts +2 -0
  53. package/{dist/builtin/internal → lib/builtin/aptos}/index.js +3 -4
  54. package/lib/builtin/aptos/index.js.map +1 -0
  55. package/lib/builtin/eacaggregatorproxy/index.d.ts +2 -0
  56. package/lib/builtin/eacaggregatorproxy/index.js +22 -0
  57. package/lib/builtin/eacaggregatorproxy/index.js.map +1 -0
  58. package/lib/builtin/eacaggregatorproxy/test-utils.d.ts +6 -0
  59. package/lib/builtin/eacaggregatorproxy/test-utils.js +57 -0
  60. package/lib/builtin/eacaggregatorproxy/test-utils.js.map +1 -0
  61. package/lib/builtin/erc1155/index.d.ts +2 -0
  62. package/lib/builtin/erc1155/index.js +22 -0
  63. package/lib/builtin/erc1155/index.js.map +1 -0
  64. package/lib/builtin/erc1155/test-utils.d.ts +6 -0
  65. package/lib/builtin/erc1155/test-utils.js +57 -0
  66. package/lib/builtin/erc1155/test-utils.js.map +1 -0
  67. package/{dist → lib}/builtin/erc20/index.d.ts +1 -1
  68. package/{dist → lib}/builtin/erc20/index.js +1 -1
  69. package/lib/builtin/erc20/index.js.map +1 -0
  70. package/lib/builtin/erc20/test-utils.d.ts +5 -0
  71. package/lib/builtin/erc20/test-utils.js +46 -0
  72. package/lib/builtin/erc20/test-utils.js.map +1 -0
  73. package/lib/builtin/erc20bytes/index.d.ts +2 -0
  74. package/lib/builtin/erc20bytes/index.js +22 -0
  75. package/lib/builtin/erc20bytes/index.js.map +1 -0
  76. package/lib/builtin/erc20bytes/test-utils.d.ts +4 -0
  77. package/lib/builtin/erc20bytes/test-utils.js +35 -0
  78. package/lib/builtin/erc20bytes/test-utils.js.map +1 -0
  79. package/lib/builtin/erc721/index.d.ts +2 -0
  80. package/lib/builtin/erc721/index.js +22 -0
  81. package/lib/builtin/erc721/index.js.map +1 -0
  82. package/lib/builtin/erc721/test-utils.d.ts +5 -0
  83. package/lib/builtin/erc721/test-utils.js +46 -0
  84. package/lib/builtin/erc721/test-utils.js.map +1 -0
  85. package/lib/builtin/index.d.ts +6 -0
  86. package/lib/builtin/index.js +33 -0
  87. package/lib/builtin/index.js.map +1 -0
  88. package/lib/builtin/internal/EACAggregatorProxy.d.ts +460 -0
  89. package/lib/builtin/internal/EACAggregatorProxy.js +3 -0
  90. package/lib/builtin/internal/EACAggregatorProxy.js.map +1 -0
  91. package/lib/builtin/internal/ERC1155.d.ts +199 -0
  92. package/lib/builtin/internal/ERC1155.js +3 -0
  93. package/lib/builtin/internal/ERC1155.js.map +1 -0
  94. package/lib/builtin/internal/ERC20.d.ts +307 -0
  95. package/{dist/builtin/internal/Erc20.js → lib/builtin/internal/ERC20.js} +1 -1
  96. package/lib/builtin/internal/ERC20.js.map +1 -0
  97. package/{dist/builtin/internal/Erc20.d.ts → lib/builtin/internal/ERC20Bytes.d.ts} +62 -46
  98. package/lib/builtin/internal/ERC20Bytes.js +3 -0
  99. package/lib/builtin/internal/ERC20Bytes.js.map +1 -0
  100. package/lib/builtin/internal/ERC721.d.ts +252 -0
  101. package/lib/builtin/internal/ERC721.js +3 -0
  102. package/lib/builtin/internal/ERC721.js.map +1 -0
  103. package/lib/builtin/internal/WETH9.d.ts +221 -0
  104. package/lib/builtin/internal/WETH9.js +3 -0
  105. package/lib/builtin/internal/WETH9.js.map +1 -0
  106. package/{dist → lib}/builtin/internal/common.d.ts +0 -0
  107. package/{dist → lib}/builtin/internal/common.js +0 -0
  108. package/lib/builtin/internal/common.js.map +1 -0
  109. package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +294 -0
  110. package/lib/builtin/internal/eacaggregatorproxy_processor.js +761 -0
  111. package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -0
  112. package/lib/builtin/internal/erc1155_processor.d.ts +126 -0
  113. package/lib/builtin/internal/erc1155_processor.js +313 -0
  114. package/lib/builtin/internal/erc1155_processor.js.map +1 -0
  115. package/lib/builtin/internal/erc20_processor.d.ts +166 -0
  116. package/lib/builtin/internal/erc20_processor.js +418 -0
  117. package/lib/builtin/internal/erc20_processor.js.map +1 -0
  118. package/lib/builtin/internal/erc20bytes_processor.d.ts +101 -0
  119. package/lib/builtin/internal/erc20bytes_processor.js +311 -0
  120. package/lib/builtin/internal/erc20bytes_processor.js.map +1 -0
  121. package/lib/builtin/internal/erc721_processor.d.ts +155 -0
  122. package/lib/builtin/internal/erc721_processor.js +437 -0
  123. package/lib/builtin/internal/erc721_processor.js.map +1 -0
  124. package/lib/builtin/internal/factories/EACAggregatorProxy__factory.d.ts +46 -0
  125. package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js +528 -0
  126. package/lib/builtin/internal/factories/EACAggregatorProxy__factory.js.map +1 -0
  127. package/{dist/builtin/internal/factories/Erc20__factory.d.ts → lib/builtin/internal/factories/ERC1155__factory.d.ts} +4 -4
  128. package/lib/builtin/internal/factories/ERC1155__factory.js +333 -0
  129. package/lib/builtin/internal/factories/ERC1155__factory.js.map +1 -0
  130. package/lib/builtin/internal/factories/ERC20Bytes__factory.d.ts +48 -0
  131. package/{dist/builtin/internal/factories/Erc20__factory.js → lib/builtin/internal/factories/ERC20Bytes__factory.js} +128 -89
  132. package/lib/builtin/internal/factories/ERC20Bytes__factory.js.map +1 -0
  133. package/lib/builtin/internal/factories/ERC20__factory.d.ts +42 -0
  134. package/lib/builtin/internal/factories/ERC20__factory.js +405 -0
  135. package/lib/builtin/internal/factories/ERC20__factory.js.map +1 -0
  136. package/lib/builtin/internal/factories/ERC721__factory.d.ts +51 -0
  137. package/lib/builtin/internal/factories/ERC721__factory.js +365 -0
  138. package/lib/builtin/internal/factories/ERC721__factory.js.map +1 -0
  139. package/lib/builtin/internal/factories/WETH9__factory.d.ts +45 -0
  140. package/lib/builtin/internal/factories/WETH9__factory.js +298 -0
  141. package/lib/builtin/internal/factories/WETH9__factory.js.map +1 -0
  142. package/lib/builtin/internal/factories/index.d.ts +6 -0
  143. package/lib/builtin/internal/factories/index.js +19 -0
  144. package/lib/builtin/internal/factories/index.js.map +1 -0
  145. package/lib/builtin/internal/index.d.ts +13 -0
  146. package/lib/builtin/internal/index.js +40 -0
  147. package/lib/builtin/internal/index.js.map +1 -0
  148. package/lib/builtin/internal/weth9_processor.d.ts +115 -0
  149. package/lib/builtin/internal/weth9_processor.js +353 -0
  150. package/lib/builtin/internal/weth9_processor.js.map +1 -0
  151. package/lib/builtin/solana/index.d.ts +2 -0
  152. package/lib/builtin/solana/index.js +19 -0
  153. package/lib/builtin/solana/index.js.map +1 -0
  154. package/lib/builtin/solana/spl-token-processor.d.ts +39 -0
  155. package/lib/builtin/solana/spl-token-processor.js +258 -0
  156. package/lib/builtin/solana/spl-token-processor.js.map +1 -0
  157. package/lib/builtin/solana/types.d.ts +427 -0
  158. package/lib/builtin/solana/types.js +203 -0
  159. package/lib/builtin/solana/types.js.map +1 -0
  160. package/lib/builtin/solana/wormhole-processor.d.ts +16 -0
  161. package/{dist/test-case/types/wormhole_processor.js → lib/builtin/solana/wormhole-processor.js} +57 -54
  162. package/lib/builtin/solana/wormhole-processor.js.map +1 -0
  163. package/lib/builtin/weth9/index.d.ts +2 -0
  164. package/lib/builtin/weth9/index.js +22 -0
  165. package/lib/builtin/weth9/index.js.map +1 -0
  166. package/lib/builtin/weth9/test-utils.d.ts +6 -0
  167. package/lib/builtin/weth9/test-utils.js +57 -0
  168. package/lib/builtin/weth9/test-utils.js.map +1 -0
  169. package/lib/chain-config.d.ts +6 -0
  170. package/lib/chain-config.js +3 -0
  171. package/lib/chain-config.js.map +1 -0
  172. package/lib/core/account-processor.d.ts +58 -0
  173. package/lib/core/account-processor.js +147 -0
  174. package/lib/core/account-processor.js.map +1 -0
  175. package/lib/core/base-context.d.ts +12 -0
  176. package/lib/core/base-context.js +25 -0
  177. package/lib/core/base-context.js.map +1 -0
  178. package/lib/core/base-processor-template.d.ts +42 -0
  179. package/{dist → lib/core}/base-processor-template.js +32 -6
  180. package/lib/core/base-processor-template.js.map +1 -0
  181. package/lib/core/base-processor.d.ts +39 -0
  182. package/lib/core/base-processor.js +153 -0
  183. package/lib/core/base-processor.js.map +1 -0
  184. package/lib/core/big-decimal.d.ts +1 -0
  185. package/lib/core/big-decimal.js +6 -0
  186. package/lib/core/big-decimal.js.map +1 -0
  187. package/{dist → lib/core}/bind-options.d.ts +5 -0
  188. package/{dist → lib/core}/bind-options.js +10 -1
  189. package/lib/core/bind-options.js.map +1 -0
  190. package/lib/core/context.d.ts +55 -0
  191. package/lib/core/context.js +162 -0
  192. package/lib/core/context.js.map +1 -0
  193. package/lib/core/eth-plugin.d.ts +14 -0
  194. package/lib/core/eth-plugin.js +221 -0
  195. package/lib/core/eth-plugin.js.map +1 -0
  196. package/lib/core/event-tracker.d.ts +26 -0
  197. package/lib/core/event-tracker.js +54 -0
  198. package/lib/core/event-tracker.js.map +1 -0
  199. package/lib/core/exporter.d.ts +13 -0
  200. package/lib/core/exporter.js +30 -0
  201. package/lib/core/exporter.js.map +1 -0
  202. package/lib/core/generic-processor.d.ts +10 -0
  203. package/lib/core/generic-processor.js +32 -0
  204. package/lib/core/generic-processor.js.map +1 -0
  205. package/{dist/test-case/erc20-template.test.d.ts → lib/core/generic-processor.test.d.ts} +0 -0
  206. package/lib/core/generic-processor.test.js.map +1 -0
  207. package/lib/core/index.d.ts +17 -0
  208. package/lib/core/index.js +46 -0
  209. package/lib/core/index.js.map +1 -0
  210. package/lib/core/logger.d.ts +14 -0
  211. package/lib/core/logger.js +42 -0
  212. package/lib/core/logger.js.map +1 -0
  213. package/lib/core/metadata.d.ts +7 -0
  214. package/lib/core/metadata.js +12 -0
  215. package/lib/core/metadata.js.map +1 -0
  216. package/lib/core/meter.d.ts +59 -0
  217. package/lib/core/meter.js +166 -0
  218. package/lib/core/meter.js.map +1 -0
  219. package/{dist/test-case/erc20.test.d.ts → lib/core/meter.test.d.ts} +0 -0
  220. package/lib/core/meter.test.js.map +1 -0
  221. package/lib/core/numberish.d.ts +8 -0
  222. package/lib/core/numberish.js +115 -0
  223. package/lib/core/numberish.js.map +1 -0
  224. package/{dist/test-case/mirrorworld.d.ts → lib/core/numberish.test.d.ts} +0 -0
  225. package/lib/core/numberish.test.js.map +1 -0
  226. package/lib/core/solana-context.d.ts +12 -0
  227. package/lib/core/solana-context.js +34 -0
  228. package/lib/core/solana-context.js.map +1 -0
  229. package/lib/core/solana-options.d.ts +9 -0
  230. package/lib/core/solana-options.js +13 -0
  231. package/lib/core/solana-options.js.map +1 -0
  232. package/lib/core/solana-plugin.d.ts +9 -0
  233. package/lib/core/solana-plugin.js +79 -0
  234. package/lib/core/solana-plugin.js.map +1 -0
  235. package/lib/core/solana-processor.d.ts +41 -0
  236. package/lib/core/solana-processor.js +90 -0
  237. package/lib/core/solana-processor.js.map +1 -0
  238. package/lib/core/sui-plugin.d.ts +8 -0
  239. package/lib/core/sui-plugin.js +46 -0
  240. package/lib/core/sui-plugin.js.map +1 -0
  241. package/lib/core/sui-processor.d.ts +26 -0
  242. package/lib/core/sui-processor.js +59 -0
  243. package/lib/core/sui-processor.js.map +1 -0
  244. package/lib/core/trace.d.ts +35 -0
  245. package/lib/core/trace.js +43 -0
  246. package/lib/core/trace.js.map +1 -0
  247. package/lib/endpoints.d.ts +6 -0
  248. package/lib/endpoints.js +11 -0
  249. package/lib/endpoints.js.map +1 -0
  250. package/lib/error.d.ts +7 -0
  251. package/lib/error.js +43 -0
  252. package/lib/error.js.map +1 -0
  253. package/{dist → lib}/gen/builtin.d.ts +0 -0
  254. package/{dist → lib}/gen/builtin.js +0 -0
  255. package/lib/gen/builtin.js.map +1 -0
  256. package/lib/gen/chainquery/protos/chainquery.d.ts +400 -0
  257. package/lib/gen/chainquery/protos/chainquery.js +972 -0
  258. package/lib/gen/chainquery/protos/chainquery.js.map +1 -0
  259. package/{dist → lib}/gen/google/protobuf/empty.d.ts +0 -0
  260. package/{dist → lib}/gen/google/protobuf/empty.js +0 -0
  261. package/lib/gen/google/protobuf/empty.js.map +1 -0
  262. package/lib/gen/google/protobuf/struct.d.ts +73 -0
  263. package/lib/gen/google/protobuf/struct.js +371 -0
  264. package/lib/gen/google/protobuf/struct.js.map +1 -0
  265. package/lib/gen/google/protobuf/timestamp.d.ts +18 -0
  266. package/lib/gen/google/protobuf/timestamp.js +71 -0
  267. package/lib/gen/google/protobuf/timestamp.js.map +1 -0
  268. package/lib/gen/index.d.ts +2 -0
  269. package/lib/gen/index.js +19 -0
  270. package/lib/gen/index.js.map +1 -0
  271. package/lib/gen/processor/protos/processor.d.ts +826 -0
  272. package/lib/gen/processor/protos/processor.js +3988 -0
  273. package/lib/gen/processor/protos/processor.js.map +1 -0
  274. package/lib/gen/service/price/protos/price.d.ts +85 -0
  275. package/lib/gen/service/price/protos/price.js +269 -0
  276. package/lib/gen/service/price/protos/price.js.map +1 -0
  277. package/lib/index.d.ts +7 -0
  278. package/lib/index.js +48 -0
  279. package/lib/index.js.map +1 -0
  280. package/lib/loader.d.ts +5 -0
  281. package/lib/loader.js +30 -0
  282. package/lib/loader.js.map +1 -0
  283. package/lib/plugin.d.ts +15 -0
  284. package/lib/plugin.js +32 -0
  285. package/lib/plugin.js.map +1 -0
  286. package/{dist → lib}/processor-runner.d.ts +0 -0
  287. package/lib/processor-runner.js +102 -0
  288. package/lib/processor-runner.js.map +1 -0
  289. package/lib/promise-or-void.d.ts +1 -0
  290. package/lib/promise-or-void.js +3 -0
  291. package/lib/promise-or-void.js.map +1 -0
  292. package/{dist → lib}/provider.d.ts +2 -1
  293. package/{dist → lib}/provider.js +19 -9
  294. package/lib/provider.js.map +1 -0
  295. package/lib/service.d.ts +26 -0
  296. package/lib/service.js +225 -0
  297. package/lib/service.js.map +1 -0
  298. package/lib/solana-codegen/codegen.d.ts +1 -0
  299. package/lib/solana-codegen/codegen.js +113 -0
  300. package/lib/solana-codegen/codegen.js.map +1 -0
  301. package/lib/state/processor-state.d.ts +3 -0
  302. package/lib/state/processor-state.js +8 -0
  303. package/lib/state/processor-state.js.map +1 -0
  304. package/lib/state/state-storage.d.ts +17 -0
  305. package/lib/state/state-storage.js +60 -0
  306. package/lib/state/state-storage.js.map +1 -0
  307. package/{dist/test-case/solana.test.d.ts → lib/state/state-storage.test.d.ts} +0 -0
  308. package/lib/state/state-storage.test.js.map +1 -0
  309. package/lib/target-ethers-sentio/event-handler.d.ts +3 -0
  310. package/lib/target-ethers-sentio/event-handler.js +35 -0
  311. package/lib/target-ethers-sentio/event-handler.js.map +1 -0
  312. package/{dist/target-ethers-sentio/codegen.d.ts → lib/target-ethers-sentio/file.d.ts} +1 -0
  313. package/lib/target-ethers-sentio/file.js +226 -0
  314. package/lib/target-ethers-sentio/file.js.map +1 -0
  315. package/lib/target-ethers-sentio/functions-handler.d.ts +3 -0
  316. package/lib/target-ethers-sentio/functions-handler.js +50 -0
  317. package/lib/target-ethers-sentio/functions-handler.js.map +1 -0
  318. package/{dist → lib}/target-ethers-sentio/index.d.ts +1 -0
  319. package/{dist → lib}/target-ethers-sentio/index.js +16 -3
  320. package/{dist → lib}/target-ethers-sentio/index.js.map +1 -1
  321. package/lib/target-ethers-sentio/types.d.ts +4 -0
  322. package/lib/target-ethers-sentio/types.js +46 -0
  323. package/lib/target-ethers-sentio/types.js.map +1 -0
  324. package/lib/target-ethers-sentio/view-function.d.ts +5 -0
  325. package/lib/target-ethers-sentio/view-function.js +74 -0
  326. package/lib/target-ethers-sentio/view-function.js.map +1 -0
  327. package/{dist/cli/cli.d.ts → lib/test-abi-code-gen.d.ts} +0 -0
  328. package/lib/test-abi-code-gen.js +20 -0
  329. package/lib/test-abi-code-gen.js.map +1 -0
  330. package/lib/testing/index.d.ts +2 -0
  331. package/lib/testing/index.js +11 -0
  332. package/lib/testing/index.js.map +1 -0
  333. package/lib/testing/metric-utils.d.ts +5 -0
  334. package/lib/testing/metric-utils.js +50 -0
  335. package/lib/testing/metric-utils.js.map +1 -0
  336. package/lib/testing/test-processor-server.d.ts +42 -0
  337. package/lib/testing/test-processor-server.js +293 -0
  338. package/lib/testing/test-processor-server.js.map +1 -0
  339. package/lib/testing/test-provider.d.ts +1 -0
  340. package/lib/testing/test-provider.js +33 -0
  341. package/lib/testing/test-provider.js.map +1 -0
  342. package/lib/utils/chain.d.ts +89 -0
  343. package/lib/utils/chain.js +128 -0
  344. package/lib/utils/chain.js.map +1 -0
  345. package/lib/utils/chainlink-oracles-goerli.csv +8 -0
  346. package/lib/utils/chainlink-oracles.csv +217 -0
  347. package/lib/utils/conversion.d.ts +6 -0
  348. package/lib/utils/conversion.js +27 -0
  349. package/lib/utils/conversion.js.map +1 -0
  350. package/lib/utils/dex-price.d.ts +22 -0
  351. package/lib/utils/dex-price.js +114 -0
  352. package/lib/utils/dex-price.js.map +1 -0
  353. package/{dist/test-case/wormhole-token-bridge.d.ts → lib/utils/dex-price.test.d.ts} +0 -0
  354. package/lib/utils/dex-price.test.js.map +1 -0
  355. package/lib/utils/erc20.test.d.ts +1 -0
  356. package/lib/utils/erc20.test.js.map +1 -0
  357. package/lib/utils/index.d.ts +4 -0
  358. package/lib/utils/index.js +31 -0
  359. package/lib/utils/index.js.map +1 -0
  360. package/lib/utils/price.d.ts +52 -0
  361. package/lib/utils/price.js +86 -0
  362. package/lib/utils/price.js.map +1 -0
  363. package/lib/utils/token.d.ts +15 -0
  364. package/lib/utils/token.js +60 -0
  365. package/lib/utils/token.js.map +1 -0
  366. package/package.json +43 -42
  367. package/src/abis/EACAggregatorProxy.json +227 -0
  368. package/src/abis/ERC1155.json +314 -0
  369. package/src/abis/ERC20.json +174 -0
  370. package/src/abis/ERC20Bytes.json +236 -0
  371. package/src/abis/ERC721.json +346 -0
  372. package/src/abis/WETH9.json +153 -0
  373. package/src/abis/aptos/0x1.json +9205 -0
  374. package/src/abis/aptos/0x3.json +1515 -0
  375. package/src/aptos/api.ts +11 -0
  376. package/src/aptos/aptos-plugin.ts +217 -0
  377. package/src/aptos/aptos-processor.ts +305 -0
  378. package/src/aptos/context.ts +75 -0
  379. package/src/aptos/index.ts +10 -0
  380. package/src/aptos/models.ts +34 -0
  381. package/src/aptos/network.ts +42 -0
  382. package/src/aptos/runtime.ts +13 -0
  383. package/src/aptos/type-registry.ts +187 -0
  384. package/src/aptos/types.ts +149 -0
  385. package/src/aptos/utils.ts +26 -0
  386. package/src/aptos-codegen/codegen.ts +428 -0
  387. package/src/aptos-codegen/tsconfig.json +9 -0
  388. package/src/aptos-codegen/typegen.ts +153 -0
  389. package/src/binds.ts +45 -0
  390. package/src/builtin/aptos/0x1.ts +4210 -0
  391. package/src/builtin/aptos/0x3.ts +888 -0
  392. package/src/builtin/aptos/index.ts +2 -0
  393. package/src/builtin/eacaggregatorproxy/index.ts +6 -0
  394. package/src/builtin/eacaggregatorproxy/test-utils.ts +89 -0
  395. package/src/builtin/erc1155/index.ts +6 -0
  396. package/src/builtin/erc1155/test-utils.ts +89 -0
  397. package/src/builtin/erc20/index.ts +6 -0
  398. package/src/builtin/erc20/test-utils.ts +71 -0
  399. package/src/builtin/erc20bytes/index.ts +6 -0
  400. package/src/builtin/erc20bytes/test-utils.ts +53 -0
  401. package/src/builtin/erc721/index.ts +6 -0
  402. package/src/builtin/erc721/test-utils.ts +71 -0
  403. package/src/builtin/index.ts +7 -0
  404. package/src/builtin/internal/EACAggregatorProxy.ts +861 -0
  405. package/src/builtin/internal/ERC1155.ts +529 -0
  406. package/src/builtin/internal/ERC20.ts +679 -0
  407. package/src/builtin/internal/ERC20Bytes.ts +384 -0
  408. package/src/builtin/internal/ERC721.ts +639 -0
  409. package/src/builtin/internal/WETH9.ts +480 -0
  410. package/src/builtin/internal/common.ts +46 -0
  411. package/src/builtin/internal/eacaggregatorproxy_processor.ts +1219 -0
  412. package/src/builtin/internal/erc1155_processor.ts +534 -0
  413. package/src/builtin/internal/erc20_processor.ts +663 -0
  414. package/src/builtin/internal/erc20bytes_processor.ts +474 -0
  415. package/src/builtin/internal/erc721_processor.ts +686 -0
  416. package/src/builtin/internal/factories/EACAggregatorProxy__factory.ts +534 -0
  417. package/src/builtin/internal/factories/ERC1155__factory.ts +336 -0
  418. package/src/builtin/internal/factories/ERC20Bytes__factory.ts +258 -0
  419. package/src/builtin/internal/factories/ERC20__factory.ts +405 -0
  420. package/src/builtin/internal/factories/ERC721__factory.ts +365 -0
  421. package/src/builtin/internal/factories/WETH9__factory.ts +298 -0
  422. package/src/builtin/internal/factories/index.ts +9 -0
  423. package/src/builtin/internal/index.ts +16 -0
  424. package/src/builtin/internal/weth9_processor.ts +536 -0
  425. package/src/builtin/solana/index.ts +2 -0
  426. package/src/builtin/solana/spl-token-processor.ts +298 -0
  427. package/src/builtin/solana/types.ts +279 -0
  428. package/src/builtin/solana/wormhole-processor.ts +178 -0
  429. package/src/builtin/weth9/index.ts +6 -0
  430. package/src/builtin/weth9/test-utils.ts +89 -0
  431. package/src/chain-config.ts +6 -0
  432. package/src/core/account-processor.ts +217 -0
  433. package/src/core/base-context.ts +28 -0
  434. package/src/core/base-processor-template.ts +150 -0
  435. package/src/core/base-processor.ts +217 -0
  436. package/src/core/big-decimal.ts +1 -0
  437. package/src/core/bind-options.ts +45 -0
  438. package/src/core/context.ts +183 -0
  439. package/src/core/eth-plugin.ts +255 -0
  440. package/src/core/event-tracker.ts +69 -0
  441. package/src/core/exporter.ts +32 -0
  442. package/src/core/generic-processor.ts +34 -0
  443. package/src/core/index.ts +22 -0
  444. package/src/core/logger.ts +49 -0
  445. package/src/core/metadata.ts +11 -0
  446. package/src/core/meter.ts +179 -0
  447. package/src/core/numberish.ts +121 -0
  448. package/src/core/solana-context.ts +35 -0
  449. package/src/core/solana-options.ts +10 -0
  450. package/src/core/solana-plugin.ts +97 -0
  451. package/src/core/solana-processor.ts +109 -0
  452. package/src/core/sui-plugin.ts +54 -0
  453. package/src/core/sui-processor.ts +65 -0
  454. package/src/core/trace.ts +86 -0
  455. package/src/endpoints.ts +9 -0
  456. package/src/error.ts +45 -0
  457. package/src/gen/builtin.ts +22 -0
  458. package/src/gen/chainquery/protos/chainquery.ts +1212 -0
  459. package/src/gen/google/protobuf/empty.ts +58 -0
  460. package/src/gen/google/protobuf/struct.ts +422 -0
  461. package/src/gen/google/protobuf/timestamp.ts +85 -0
  462. package/src/gen/index.ts +3 -0
  463. package/src/gen/processor/protos/processor.ts +4619 -0
  464. package/src/gen/service/price/protos/price.ts +329 -0
  465. package/src/index.ts +13 -0
  466. package/src/loader.ts +24 -0
  467. package/src/plugin.ts +41 -0
  468. package/src/processor-runner.ts +93 -0
  469. package/src/promise-or-void.ts +1 -0
  470. package/src/provider.ts +74 -0
  471. package/src/service.ts +255 -0
  472. package/src/solana-codegen/codegen.ts +116 -0
  473. package/src/state/processor-state.ts +3 -0
  474. package/src/state/state-storage.ts +65 -0
  475. package/src/target-ethers-sentio/event-handler.ts +31 -0
  476. package/src/target-ethers-sentio/file.ts +242 -0
  477. package/src/target-ethers-sentio/functions-handler.ts +57 -0
  478. package/src/target-ethers-sentio/index.ts +60 -0
  479. package/src/target-ethers-sentio/tsconfig.json +9 -0
  480. package/src/target-ethers-sentio/types.ts +42 -0
  481. package/src/target-ethers-sentio/view-function.ts +79 -0
  482. package/src/test-abi-code-gen.ts +16 -0
  483. package/src/testing/index.ts +4 -0
  484. package/src/testing/metric-utils.ts +48 -0
  485. package/src/testing/test-processor-server.ts +334 -0
  486. package/src/testing/test-provider.ts +33 -0
  487. package/src/types/global.d.ts +15 -0
  488. package/src/utils/chain.ts +127 -0
  489. package/src/utils/chainlink-oracles-goerli.csv +8 -0
  490. package/src/utils/chainlink-oracles.csv +217 -0
  491. package/src/utils/conversion.ts +27 -0
  492. package/src/utils/dex-price.ts +136 -0
  493. package/src/utils/index.ts +4 -0
  494. package/src/utils/price.ts +95 -0
  495. package/src/utils/token.ts +70 -0
  496. package/dist/base-processor-template.d.ts +0 -20
  497. package/dist/base-processor-template.js.map +0 -1
  498. package/dist/base-processor.d.ts +0 -22
  499. package/dist/base-processor.js +0 -103
  500. package/dist/base-processor.js.map +0 -1
  501. package/dist/bind-options.js.map +0 -1
  502. package/dist/binds.d.ts +0 -10
  503. package/dist/binds.js +0 -58
  504. package/dist/binds.js.map +0 -1
  505. package/dist/builtin/erc20/index.js.map +0 -1
  506. package/dist/builtin/internal/Erc20.js.map +0 -1
  507. package/dist/builtin/internal/common.js.map +0 -1
  508. package/dist/builtin/internal/erc20_processor.d.ts +0 -38
  509. package/dist/builtin/internal/erc20_processor.js +0 -209
  510. package/dist/builtin/internal/erc20_processor.js.map +0 -1
  511. package/dist/builtin/internal/factories/Erc20__factory.js.map +0 -1
  512. package/dist/builtin/internal/factories/index.d.ts +0 -1
  513. package/dist/builtin/internal/factories/index.js +0 -9
  514. package/dist/builtin/internal/factories/index.js.map +0 -1
  515. package/dist/builtin/internal/index.d.ts +0 -3
  516. package/dist/builtin/internal/index.js.map +0 -1
  517. package/dist/cli/build.d.ts +0 -3
  518. package/dist/cli/build.js +0 -161
  519. package/dist/cli/build.js.map +0 -1
  520. package/dist/cli/cli.js +0 -212
  521. package/dist/cli/cli.js.map +0 -1
  522. package/dist/cli/config.d.ts +0 -14
  523. package/dist/cli/config.js +0 -24
  524. package/dist/cli/config.js.map +0 -1
  525. package/dist/cli/key.d.ts +0 -2
  526. package/dist/cli/key.js +0 -44
  527. package/dist/cli/key.js.map +0 -1
  528. package/dist/cli/solana-code-gen.d.ts +0 -2
  529. package/dist/cli/solana-code-gen.js +0 -19
  530. package/dist/cli/solana-code-gen.js.map +0 -1
  531. package/dist/cli/upload.d.ts +0 -2
  532. package/dist/cli/upload.js +0 -76
  533. package/dist/cli/upload.js.map +0 -1
  534. package/dist/cli/webpack.config.js +0 -41
  535. package/dist/context.d.ts +0 -39
  536. package/dist/context.js +0 -75
  537. package/dist/context.js.map +0 -1
  538. package/dist/contract-namer.d.ts +0 -6
  539. package/dist/contract-namer.js +0 -20
  540. package/dist/contract-namer.js.map +0 -1
  541. package/dist/error.d.ts +0 -2
  542. package/dist/error.js +0 -39
  543. package/dist/error.js.map +0 -1
  544. package/dist/gen/builtin.js.map +0 -1
  545. package/dist/gen/google/protobuf/empty.js.map +0 -1
  546. package/dist/gen/processor/protos/processor.d.ts +0 -598
  547. package/dist/gen/processor/protos/processor.js +0 -2424
  548. package/dist/gen/processor/protos/processor.js.map +0 -1
  549. package/dist/index.d.ts +0 -13
  550. package/dist/index.js +0 -54
  551. package/dist/index.js.map +0 -1
  552. package/dist/meter.d.ts +0 -25
  553. package/dist/meter.js +0 -114
  554. package/dist/meter.js.map +0 -1
  555. package/dist/numberish.d.ts +0 -7
  556. package/dist/numberish.js +0 -74
  557. package/dist/numberish.js.map +0 -1
  558. package/dist/numberish.test.js +0 -54
  559. package/dist/numberish.test.js.map +0 -1
  560. package/dist/processor-runner.js +0 -66
  561. package/dist/processor-runner.js.map +0 -1
  562. package/dist/processor-state.d.ts +0 -16
  563. package/dist/processor-state.js +0 -20
  564. package/dist/processor-state.js.map +0 -1
  565. package/dist/provider.js.map +0 -1
  566. package/dist/service.d.ts +0 -22
  567. package/dist/service.js +0 -361
  568. package/dist/service.js.map +0 -1
  569. package/dist/solana/builtin/spl-token-processor.d.ts +0 -25
  570. package/dist/solana/builtin/spl-token-processor.js +0 -152
  571. package/dist/solana/builtin/spl-token-processor.js.map +0 -1
  572. package/dist/solana-processor.d.ts +0 -28
  573. package/dist/solana-processor.js +0 -79
  574. package/dist/solana-processor.js.map +0 -1
  575. package/dist/target-ethers-sentio/codegen.js +0 -201
  576. package/dist/target-ethers-sentio/codegen.js.map +0 -1
  577. package/dist/test-case/clean-test.d.ts +0 -1
  578. package/dist/test-case/clean-test.js +0 -9
  579. package/dist/test-case/clean-test.js.map +0 -1
  580. package/dist/test-case/erc20-template.d.ts +0 -1
  581. package/dist/test-case/erc20-template.js +0 -23
  582. package/dist/test-case/erc20-template.js.map +0 -1
  583. package/dist/test-case/erc20-template.test.js +0 -69
  584. package/dist/test-case/erc20-template.test.js.map +0 -1
  585. package/dist/test-case/erc20.d.ts +0 -1
  586. package/dist/test-case/erc20.js +0 -42
  587. package/dist/test-case/erc20.js.map +0 -1
  588. package/dist/test-case/erc20.test.js +0 -154
  589. package/dist/test-case/erc20.test.js.map +0 -1
  590. package/dist/test-case/mirrorworld.js +0 -42
  591. package/dist/test-case/mirrorworld.js.map +0 -1
  592. package/dist/test-case/solana.test.js +0 -58
  593. package/dist/test-case/solana.test.js.map +0 -1
  594. package/dist/test-case/types/game_wallet.d.ts +0 -45
  595. package/dist/test-case/types/game_wallet.js +0 -1396
  596. package/dist/test-case/types/game_wallet.js.map +0 -1
  597. package/dist/test-case/types/game_wallet_processor.d.ts +0 -107
  598. package/dist/test-case/types/game_wallet_processor.js +0 -102
  599. package/dist/test-case/types/game_wallet_processor.js.map +0 -1
  600. package/dist/test-case/types/wormhole_processor.d.ts +0 -16
  601. package/dist/test-case/types/wormhole_processor.js.map +0 -1
  602. package/dist/test-case/wormhole-token-bridge.js +0 -7
  603. package/dist/test-case/wormhole-token-bridge.js.map +0 -1
  604. package/dist/utils/chainmap.d.ts +0 -4
  605. package/dist/utils/chainmap.js +0 -95
  606. package/dist/utils/chainmap.js.map +0 -1
  607. package/dist/utils/index.d.ts +0 -1
  608. package/dist/utils/index.js +0 -6
  609. package/dist/utils/index.js.map +0 -1
@@ -0,0 +1,178 @@
1
+ import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from '@sentio/sdk'
2
+ import { Instruction } from '@project-serum/anchor'
3
+ import * as borsh from "@coral-xyz/borsh";
4
+ import bs58 from 'bs58'
5
+
6
+ // https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/lib.rs#L100
7
+ enum TokenBridgeInstruction {
8
+ Initialize = 0,
9
+ AttestToken,
10
+ CompleteNative, // no args
11
+ CompleteWrapped, // no args
12
+ TransferWrapped,
13
+ TransferNative,
14
+ RegisterChain, // no args
15
+ CreateWrapped, // no args
16
+ UpgradeContract, // no args
17
+ CompleteNativeWithPayload, // no args
18
+ CompleteWrappedWithPayload, // no args
19
+ TransferWrappedWithPayload,
20
+ TransferNativeWithPayload,
21
+ }
22
+
23
+ export class TokenBridgeProcessor extends SolanaBaseProcessor {
24
+
25
+ private readonly transferDataValues = [
26
+ borsh.u32('nonce'),
27
+ borsh.u64('amount'),
28
+ borsh.u64('fee'),
29
+ borsh.array(borsh.u8(undefined), 32, 'target_address'),
30
+ borsh.u16('target_chain')
31
+ ]
32
+ // https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer_payload.rs#L170
33
+ private readonly transferDataWithPayloadValues = [
34
+ borsh.u32('nonce'),
35
+ borsh.u64('amount'),
36
+ borsh.array(borsh.u8(undefined), 32, 'target_address'),
37
+ borsh.u16('target_chain'),
38
+ borsh.vecU8('payload'),
39
+ borsh.option(borsh.publicKey(undefined), 'cpi_program_id')
40
+ ]
41
+ private readonly attestTokenValues = [
42
+ borsh.u32('nonce')
43
+ ]
44
+ private readonly initializeDataValues = [
45
+ borsh.publicKey('bridge')
46
+ ]
47
+
48
+ static bind(options: SolanaBindOptions): TokenBridgeProcessor {
49
+ if (options && !options.name) {
50
+ options.name = 'WormholeTokenBridge'
51
+ }
52
+ return new TokenBridgeProcessor(options)
53
+ }
54
+
55
+ decodeInstruction: (rawInstruction: string) => Instruction | null = (ins) => {
56
+ const u8Arr = bs58.decode(ins)
57
+ if (u8Arr.length === 0) {
58
+ return null
59
+ }
60
+
61
+ let data: any
62
+ // wormhole pass intruction's enum value as its first instrcution data
63
+ switch (u8Arr[0]) {
64
+ case TokenBridgeInstruction.Initialize:
65
+ return {
66
+ data: '',
67
+ name: TokenBridgeInstruction[TokenBridgeInstruction.Initialize]
68
+ }
69
+ case TokenBridgeInstruction.TransferNative:
70
+ // struct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
71
+ data = borsh.struct(this.transferDataValues, 'TransferNativeData').decode(Buffer.from(u8Arr.slice(1)))
72
+ return {
73
+ data,
74
+ name: TokenBridgeInstruction[TokenBridgeInstruction.TransferNative]
75
+ }
76
+ case TokenBridgeInstruction.TransferWrapped:
77
+ // stuct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
78
+ data = borsh.struct(this.transferDataValues, 'TransferWrappedData').decode(Buffer.from(u8Arr.slice(1)))
79
+ return {
80
+ data,
81
+ name: TokenBridgeInstruction[TokenBridgeInstruction.TransferWrapped]
82
+ }
83
+ case TokenBridgeInstruction.TransferNativeWithPayload:
84
+ data = borsh.struct(this.transferDataWithPayloadValues, 'TransferNativeWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
85
+ return {
86
+ data,
87
+ name: TokenBridgeInstruction[TokenBridgeInstruction.TransferNativeWithPayload]
88
+ }
89
+ case TokenBridgeInstruction.TransferWrappedWithPayload:
90
+ data = borsh.struct(this.transferDataWithPayloadValues, 'TransferWrappedWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
91
+ return {
92
+ data,
93
+ name: TokenBridgeInstruction[TokenBridgeInstruction.TransferWrappedWithPayload]
94
+ }
95
+ case TokenBridgeInstruction.Initialize:
96
+ data = borsh.struct(this.initializeDataValues, 'InitializeData').decode(Buffer.from(u8Arr.slice(1)))
97
+ return {
98
+ data,
99
+ name: TokenBridgeInstruction[TokenBridgeInstruction.Initialize]
100
+ }
101
+ case TokenBridgeInstruction.AttestToken:
102
+ data = borsh.struct(this.attestTokenValues, 'AttestTokenData').decode(Buffer.from(u8Arr.slice(1)))
103
+ return {
104
+ data,
105
+ name: TokenBridgeInstruction[TokenBridgeInstruction.AttestToken]
106
+ }
107
+ case TokenBridgeInstruction.CompleteNative:
108
+ case TokenBridgeInstruction.CompleteNativeWithPayload:
109
+ case TokenBridgeInstruction.CompleteWrapped:
110
+ case TokenBridgeInstruction.CompleteWrappedWithPayload:
111
+ case TokenBridgeInstruction.CreateWrapped:
112
+ case TokenBridgeInstruction.UpgradeContract:
113
+ case TokenBridgeInstruction.RegisterChain:
114
+ return {
115
+ data: '',
116
+ name: TokenBridgeInstruction[u8Arr[0]]
117
+ }
118
+
119
+ default:
120
+ return null
121
+ }
122
+ }
123
+
124
+ onInitialize(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
125
+ this.onInstruction('Initialize', (ins: Instruction, ctx, accounts: string[]) => {
126
+ if (ins) {
127
+ handler(ins.data, accounts, ctx)
128
+ }
129
+ })
130
+ return this
131
+ }
132
+
133
+ onAttestToken(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
134
+ this.onInstruction('AttestToken', (ins: Instruction, ctx, accounts: string[]) => {
135
+ if (ins) {
136
+ handler(ins.data, accounts, ctx)
137
+ }
138
+ })
139
+ return this
140
+ }
141
+
142
+
143
+ onTransferWrapped(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
144
+ this.onInstruction('TransferWrapped', (ins: Instruction, ctx, accounts: string[]) => {
145
+ if (ins) {
146
+ handler(ins.data, accounts, ctx)
147
+ }
148
+ })
149
+ return this
150
+ }
151
+
152
+ onTransferNativeWithPayload(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
153
+ this.onInstruction('TransferNativeWithPayload', (ins: Instruction, ctx, accounts: string[]) => {
154
+ if (ins) {
155
+ handler(ins.data, accounts, ctx)
156
+ }
157
+ })
158
+ return this
159
+ }
160
+
161
+ onTransferWrappedWithPaylod(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
162
+ this.onInstruction('TransferWrappedWithPaylod', (ins: Instruction, ctx, accounts: string[]) => {
163
+ if (ins) {
164
+ handler(ins.data, accounts, ctx)
165
+ }
166
+ })
167
+ return this
168
+ }
169
+
170
+ onTransferNative(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
171
+ this.onInstruction('TransferNative', (ins: Instruction, ctx, accounts: string[]) => {
172
+ if (ins) {
173
+ handler(ins.data, accounts, ctx)
174
+ }
175
+ })
176
+ return this
177
+ }
178
+ }
@@ -0,0 +1,6 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+
5
+ export * from "../internal/weth9_processor";
6
+ export * from "../internal/WETH9";
@@ -0,0 +1,89 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ import { Log } from "@ethersproject/providers";
5
+ import {
6
+ getWETH9Contract,
7
+ ApprovalEventObject,
8
+ TransferEventObject,
9
+ DepositEventObject,
10
+ WithdrawalEventObject,
11
+ } from ".";
12
+ const mockField = {
13
+ blockHash:
14
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
15
+ blockNumber: 0,
16
+ logIndex: 0,
17
+ removed: false,
18
+ transactionHash:
19
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
20
+ transactionIndex: 0,
21
+ };
22
+
23
+ export function mockApprovalLog(
24
+ contractAddress: string,
25
+ event: ApprovalEventObject
26
+ ): Log {
27
+ const contract = getWETH9Contract(contractAddress);
28
+ const encodedLog = contract.rawContract.interface.encodeEventLog(
29
+ contract.rawContract.interface.getEvent("Approval"),
30
+ [event.src, event.guy, event.wad]
31
+ );
32
+ return {
33
+ ...mockField,
34
+ address: contractAddress,
35
+ data: encodedLog.data,
36
+ topics: encodedLog.topics,
37
+ };
38
+ }
39
+
40
+ export function mockTransferLog(
41
+ contractAddress: string,
42
+ event: TransferEventObject
43
+ ): Log {
44
+ const contract = getWETH9Contract(contractAddress);
45
+ const encodedLog = contract.rawContract.interface.encodeEventLog(
46
+ contract.rawContract.interface.getEvent("Transfer"),
47
+ [event.src, event.dst, event.wad]
48
+ );
49
+ return {
50
+ ...mockField,
51
+ address: contractAddress,
52
+ data: encodedLog.data,
53
+ topics: encodedLog.topics,
54
+ };
55
+ }
56
+
57
+ export function mockDepositLog(
58
+ contractAddress: string,
59
+ event: DepositEventObject
60
+ ): Log {
61
+ const contract = getWETH9Contract(contractAddress);
62
+ const encodedLog = contract.rawContract.interface.encodeEventLog(
63
+ contract.rawContract.interface.getEvent("Deposit"),
64
+ [event.dst, event.wad]
65
+ );
66
+ return {
67
+ ...mockField,
68
+ address: contractAddress,
69
+ data: encodedLog.data,
70
+ topics: encodedLog.topics,
71
+ };
72
+ }
73
+
74
+ export function mockWithdrawalLog(
75
+ contractAddress: string,
76
+ event: WithdrawalEventObject
77
+ ): Log {
78
+ const contract = getWETH9Contract(contractAddress);
79
+ const encodedLog = contract.rawContract.interface.encodeEventLog(
80
+ contract.rawContract.interface.getEvent("Withdrawal"),
81
+ [event.src, event.wad]
82
+ );
83
+ return {
84
+ ...mockField,
85
+ address: contractAddress,
86
+ data: encodedLog.data,
87
+ topics: encodedLog.topics,
88
+ };
89
+ }
@@ -0,0 +1,6 @@
1
+ export interface ChainConfig {
2
+ ChainID: string
3
+ Https: string[]
4
+ WebSockets?: string[]
5
+ ChainServer?: string
6
+ }
@@ -0,0 +1,217 @@
1
+ import { ListStateStorage } from '../state/state-storage'
2
+ import { ERC20__factory, ERC721__factory } from '../builtin/internal'
3
+ import { AddressType, DummyProvider, ProcessResult } from '@sentio/sdk'
4
+ import { AccountBindOptions } from './bind-options'
5
+ import { getNetwork } from '@ethersproject/providers'
6
+ import { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20'
7
+ import { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721'
8
+ import { AccountContext } from './context'
9
+ import { PromiseOrVoid } from '../promise-or-void'
10
+ import { Event } from '@ethersproject/contracts'
11
+ import { BytesLike } from '@ethersproject/bytes'
12
+ import { AddressOrTypeEventFilter, EventsHandler } from './base-processor'
13
+
14
+ export class AccountProcessorState extends ListStateStorage<AccountProcessor> {
15
+ static INSTANCE = new AccountProcessorState()
16
+ }
17
+
18
+ const ERC20_CONTRACT = ERC20__factory.connect('', DummyProvider)
19
+ const ERC721_CONTRACT = ERC721__factory.connect('', DummyProvider)
20
+
21
+ export class AccountProcessor {
22
+ config: AccountBindOptions
23
+ eventHandlers: EventsHandler[] = []
24
+
25
+ static bind(config: AccountBindOptions): AccountProcessor {
26
+ const processor = new AccountProcessor(config)
27
+ AccountProcessorState.INSTANCE.addValue(processor)
28
+ return processor
29
+ }
30
+
31
+ protected constructor(config: AccountBindOptions) {
32
+ this.config = config
33
+ }
34
+
35
+ public getChainId(): number {
36
+ return getNetwork(this.config.network || 1).chainId
37
+ }
38
+
39
+ /**
40
+ * Register custom handler function to process erc20 transfer event to this account
41
+ * @param handler custom handler function
42
+ * @param tokensAddresses all the erc20 token address to watch
43
+ */
44
+ onERC20TransferIn(
45
+ handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
46
+ tokensAddresses: string[] = []
47
+ ) {
48
+ return this.onERC20(handler, tokensAddresses, (address: string) =>
49
+ ERC20_CONTRACT.filters.Transfer(null, this.config.address)
50
+ )
51
+ }
52
+
53
+ /**
54
+ * Register custom handler function to process erc20 transfer event from this account
55
+ * @param handler custom handler function
56
+ * @param tokensAddresses all the erc20 token address to watch
57
+ */
58
+ onERC20TransferOut(
59
+ handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
60
+ tokensAddresses: string[] = []
61
+ ) {
62
+ return this.onERC20(handler, tokensAddresses, (address: string) =>
63
+ ERC20_CONTRACT.filters.Transfer(this.config.address)
64
+ )
65
+ }
66
+
67
+ /**
68
+ * Register custom handler function to process erc20 mint for this account
69
+ * @param handler custom handler function
70
+ * @param tokensAddresses all the erc20 token address to watch
71
+ */
72
+ onERC20Minted(
73
+ handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
74
+ tokensAddresses: string[] = []
75
+ ) {
76
+ return this.onERC20(handler, tokensAddresses, (address: string) =>
77
+ ERC20_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address)
78
+ )
79
+ }
80
+
81
+ private onERC20(
82
+ handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
83
+ tokensAddresses: string[] = [],
84
+ defaultFilter: (address: string) => AddressOrTypeEventFilter
85
+ ) {
86
+ return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20)
87
+ }
88
+
89
+ /**
90
+ * Register custom handler function to process ERC721 transfer event to this account
91
+ * @param handler custom handler function
92
+ * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
93
+ */
94
+ onERC721TransferIn(
95
+ handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
96
+ collections: string[]
97
+ ) {
98
+ return this.onERC721(handler, collections, (address: string) =>
99
+ ERC721_CONTRACT.filters.Transfer(null, this.config.address)
100
+ )
101
+ }
102
+
103
+ /**
104
+ * Register custom handler function to process ERC721 transfer event from this account
105
+ * @param handler custom handler function
106
+ * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
107
+ */
108
+ onERC721TransferOut(
109
+ handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
110
+ collections: string[]
111
+ ) {
112
+ return this.onERC721(handler, collections, (address: string) =>
113
+ ERC721_CONTRACT.filters.Transfer(this.config.address)
114
+ )
115
+ }
116
+
117
+ /**
118
+ * Register custom handler function to process ERC721 mint for this account
119
+ * @param handler custom handler function
120
+ * @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
121
+ */
122
+ onERC721Minted(
123
+ handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
124
+ collections: string[] = []
125
+ ) {
126
+ return this.onERC721(handler, collections, (address: string) =>
127
+ ERC721_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address)
128
+ )
129
+ }
130
+
131
+ private onERC721(
132
+ handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
133
+ collections: string[],
134
+ defaultFilter: (address: string) => AddressOrTypeEventFilter
135
+ ) {
136
+ return this.onERC(handler, collections, defaultFilter, AddressType.ERC721)
137
+ }
138
+
139
+ private onERC(
140
+ handler: (event: any, ctx: AccountContext) => PromiseOrVoid,
141
+ contractAddresses: string[],
142
+ defaultFilter: (address: string) => AddressOrTypeEventFilter,
143
+ addressType: AddressType
144
+ ) {
145
+ const filters = []
146
+ for (const token of contractAddresses) {
147
+ const filter = defaultFilter(this.config.address)
148
+ filter.address = token
149
+ filters.push(filter)
150
+ }
151
+ if (!filters.length) {
152
+ const filter = defaultFilter(this.config.address)
153
+ filter.address = undefined
154
+ filter.addressType = addressType
155
+ filters.push(filter)
156
+ }
157
+ return this.onEvent(handler, filters)
158
+ }
159
+
160
+ protected onEvent(
161
+ handler: (event: Event, ctx: AccountContext) => PromiseOrVoid,
162
+ filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[]
163
+ ) {
164
+ const chainId = this.getChainId()
165
+
166
+ let _filters: AddressOrTypeEventFilter[] = []
167
+
168
+ if (Array.isArray(filter)) {
169
+ _filters = filter
170
+ } else {
171
+ _filters.push(filter)
172
+ }
173
+
174
+ let hasVaildConfig = false
175
+ for (const filter of _filters) {
176
+ if (filter.address) {
177
+ hasVaildConfig = true
178
+ break
179
+ }
180
+ if (filter.topics && filter.topics.length) {
181
+ hasVaildConfig = true
182
+ break
183
+ }
184
+ }
185
+
186
+ if (!hasVaildConfig) {
187
+ throw Error('no valid config has been found for this account')
188
+ }
189
+
190
+ const config = this.config
191
+
192
+ this.eventHandlers.push({
193
+ filters: _filters,
194
+ handler: async function (log) {
195
+ const ctx = new AccountContext(chainId, config.address, undefined, log)
196
+ // let event: Event = <Event>deepCopy(log);
197
+ const event: Event = <Event>log
198
+ const parsed = ERC20_CONTRACT.interface.parseLog(log)
199
+ if (parsed) {
200
+ event.args = parsed.args
201
+ event.decode = (data: BytesLike, topics?: Array<any>) => {
202
+ return ERC20_CONTRACT.interface.decodeEventLog(parsed.eventFragment, data, topics)
203
+ }
204
+ event.event = parsed.name
205
+ event.eventSignature = parsed.signature
206
+
207
+ // TODO fix this bug
208
+ await handler(event, ctx)
209
+ return ctx.getProcessResult()
210
+ }
211
+ return ProcessResult.fromPartial({})
212
+ },
213
+ })
214
+
215
+ return this
216
+ }
217
+ }
@@ -0,0 +1,28 @@
1
+ import { ProcessResult, RecordMetaData } from '../gen'
2
+ import { Logger } from './logger'
3
+ import { Labels } from './metadata'
4
+ import { Meter } from './meter'
5
+
6
+ export abstract class BaseContext {
7
+ meter: Meter
8
+ logger: Logger
9
+
10
+ res: ProcessResult = {
11
+ counters: [],
12
+ events: [],
13
+ exports: [],
14
+ gauges: [],
15
+ logs: [],
16
+ }
17
+
18
+ protected constructor() {
19
+ this.meter = new Meter(this)
20
+ this.logger = new Logger(this)
21
+ }
22
+
23
+ getProcessResult(): ProcessResult {
24
+ return this.res
25
+ }
26
+
27
+ abstract getMetaData(name: string, labels: Labels): RecordMetaData
28
+ }
@@ -0,0 +1,150 @@
1
+ import { BoundContractView, ContractContext, ContractView } from './context'
2
+ import { Block } from '@ethersproject/abstract-provider'
3
+ import { BaseContract, EventFilter } from 'ethers'
4
+ import { Event } from '@ethersproject/contracts'
5
+ import { BaseProcessor } from './base-processor'
6
+ import { BindOptions, getOptionsSignature } from './bind-options'
7
+ import { HandleInterval, TemplateInstance } from '../gen'
8
+ import Long from 'long'
9
+ import { getNetwork } from '@ethersproject/providers'
10
+ import { PromiseOrVoid } from '../promise-or-void'
11
+ import { Trace } from './trace'
12
+ import { ListStateStorage } from '../state/state-storage'
13
+
14
+ export class ProcessorTemplateProcessorState extends ListStateStorage<
15
+ BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>
16
+ > {
17
+ static INSTANCE = new ProcessorTemplateProcessorState()
18
+ }
19
+
20
+ export class TemplateInstanceState extends ListStateStorage<TemplateInstance> {
21
+ static INSTANCE = new TemplateInstanceState()
22
+ }
23
+
24
+ export abstract class BaseProcessorTemplate<
25
+ TContract extends BaseContract,
26
+ TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>
27
+ > {
28
+ id: number
29
+ binds = new Set<string>()
30
+ blockHandlers: {
31
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
32
+ blockInterval?: HandleInterval
33
+ timeIntervalInMinutes?: HandleInterval
34
+ }[] = []
35
+ traceHandlers: {
36
+ signature: string
37
+ handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
38
+ }[] = []
39
+ eventHandlers: {
40
+ handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
41
+ filter: EventFilter | EventFilter[]
42
+ }[] = []
43
+
44
+ constructor() {
45
+ this.id = ProcessorTemplateProcessorState.INSTANCE.getValues().length
46
+ ProcessorTemplateProcessorState.INSTANCE.addValue(this)
47
+ }
48
+
49
+ public bind(options: BindOptions) {
50
+ const sig = getOptionsSignature(options)
51
+ if (this.binds.has(sig)) {
52
+ return
53
+ }
54
+ this.binds.add(sig)
55
+
56
+ const processor = this.bindInternal(options)
57
+
58
+ for (const eh of this.eventHandlers) {
59
+ processor.onEvent(eh.handler, eh.filter)
60
+ }
61
+ for (const bh of this.blockHandlers) {
62
+ processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)
63
+ }
64
+
65
+ const instance: TemplateInstance = {
66
+ templateId: this.id,
67
+ contract: {
68
+ address: options.address,
69
+ name: options.name || '',
70
+ chainId: options.network ? getNetwork(options.network).chainId.toString() : '1',
71
+ abi: '',
72
+ },
73
+ startBlock: Long.ZERO,
74
+ endBlock: Long.ZERO,
75
+ }
76
+ if (options.startBlock) {
77
+ if (typeof options.startBlock === 'number') {
78
+ instance.startBlock = Long.fromNumber(options.startBlock)
79
+ } else {
80
+ instance.startBlock = options.startBlock
81
+ }
82
+ }
83
+ if (options.endBlock) {
84
+ if (typeof options.endBlock === 'number') {
85
+ instance.endBlock = Long.fromNumber(options.endBlock)
86
+ } else {
87
+ instance.endBlock = options.endBlock
88
+ }
89
+ }
90
+ TemplateInstanceState.INSTANCE.addValue(instance)
91
+ return processor
92
+ }
93
+
94
+ public onEvent(
95
+ handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
96
+ filter: EventFilter | EventFilter[]
97
+ ) {
98
+ this.eventHandlers.push({
99
+ handler: handler,
100
+ filter: filter,
101
+ })
102
+ return this
103
+ }
104
+
105
+ public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {
106
+ return this.onBlockInterval(handler)
107
+ }
108
+
109
+ public onBlockInterval(
110
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
111
+ blockInterval = 1000,
112
+ backfillBlockInterval = 4000
113
+ ) {
114
+ return this.onInterval(handler, undefined, {
115
+ recentInterval: blockInterval,
116
+ backfillInterval: backfillBlockInterval,
117
+ })
118
+ }
119
+
120
+ public onTimeInterval(
121
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
122
+ timeIntervalInMinutes = 60,
123
+ backfillBlockInterval = 240
124
+ ) {
125
+ return this.onInterval(
126
+ handler,
127
+ { recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },
128
+ undefined
129
+ )
130
+ }
131
+
132
+ public onInterval(
133
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
134
+ timeInterval: HandleInterval | undefined,
135
+ blockInterval: HandleInterval | undefined
136
+ ) {
137
+ this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval })
138
+ return this
139
+ }
140
+
141
+ public onTrace(
142
+ signature: string,
143
+ handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
144
+ ) {
145
+ this.traceHandlers.push({ signature, handler })
146
+ return this
147
+ }
148
+
149
+ protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>
150
+ }