@sentio/sdk 1.7.12 → 1.7.15

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 (293) hide show
  1. package/{base-processor-template.d.ts → lib/base-processor-template.d.ts} +0 -0
  2. package/{base-processor-template.js → lib/base-processor-template.js} +0 -0
  3. package/lib/base-processor-template.js.map +1 -0
  4. package/{base-processor.d.ts → lib/base-processor.d.ts} +0 -0
  5. package/{base-processor.js → lib/base-processor.js} +0 -0
  6. package/lib/base-processor.js.map +1 -0
  7. package/{bind-options.d.ts → lib/bind-options.d.ts} +0 -0
  8. package/{bind-options.js → lib/bind-options.js} +0 -0
  9. package/lib/bind-options.js.map +1 -0
  10. package/{binds.d.ts → lib/binds.d.ts} +0 -0
  11. package/{binds.js → lib/binds.js} +0 -0
  12. package/lib/binds.js.map +1 -0
  13. package/{builtin → lib/builtin}/erc20/index.d.ts +0 -0
  14. package/{builtin → lib/builtin}/erc20/index.js +0 -0
  15. package/lib/builtin/erc20/index.js.map +1 -0
  16. package/{builtin → lib/builtin}/erc20/test-utils.d.ts +0 -0
  17. package/{builtin → lib/builtin}/erc20/test-utils.js +0 -0
  18. package/lib/builtin/erc20/test-utils.js.map +1 -0
  19. package/{builtin → lib/builtin}/internal/Erc20.d.ts +0 -0
  20. package/{builtin → lib/builtin}/internal/Erc20.js +0 -0
  21. package/lib/builtin/internal/Erc20.js.map +1 -0
  22. package/{builtin → lib/builtin}/internal/common.d.ts +0 -0
  23. package/{builtin → lib/builtin}/internal/common.js +0 -0
  24. package/lib/builtin/internal/common.js.map +1 -0
  25. package/{builtin → lib/builtin}/internal/erc20_processor.d.ts +0 -0
  26. package/{builtin → lib/builtin}/internal/erc20_processor.js +0 -0
  27. package/lib/builtin/internal/erc20_processor.js.map +1 -0
  28. package/{builtin → lib/builtin}/internal/factories/Erc20__factory.d.ts +0 -0
  29. package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js +0 -0
  30. package/lib/builtin/internal/factories/Erc20__factory.js.map +1 -0
  31. package/{builtin → lib/builtin}/internal/factories/index.d.ts +0 -0
  32. package/{builtin → lib/builtin}/internal/factories/index.js +0 -0
  33. package/{builtin → lib/builtin}/internal/factories/index.js.map +1 -1
  34. package/{builtin → lib/builtin}/internal/index.d.ts +0 -0
  35. package/{builtin → lib/builtin}/internal/index.js +0 -0
  36. package/lib/builtin/internal/index.js.map +1 -0
  37. package/{chain-config.d.ts → lib/chain-config.d.ts} +0 -0
  38. package/{chain-config.js → lib/chain-config.js} +0 -0
  39. package/lib/chain-config.js.map +1 -0
  40. package/{cli → lib/cli}/build.d.ts +0 -0
  41. package/{cli → lib/cli}/build.js +0 -0
  42. package/lib/cli/build.js.map +1 -0
  43. package/{cli → lib/cli}/cli.d.ts +0 -0
  44. package/{cli → lib/cli}/cli.js +0 -0
  45. package/lib/cli/cli.js.map +1 -0
  46. package/{cli → lib/cli}/config.d.ts +0 -0
  47. package/{cli → lib/cli}/config.js +0 -0
  48. package/lib/cli/config.js.map +1 -0
  49. package/{cli → lib/cli}/key.d.ts +0 -0
  50. package/{cli → lib/cli}/key.js +0 -0
  51. package/{cli → lib/cli}/key.js.map +1 -1
  52. package/{cli → lib/cli}/solana-code-gen.d.ts +0 -0
  53. package/{cli → lib/cli}/solana-code-gen.js +0 -0
  54. package/{cli → lib/cli}/solana-code-gen.js.map +1 -1
  55. package/{cli → lib/cli}/upload.d.ts +0 -0
  56. package/{cli → lib/cli}/upload.js +0 -0
  57. package/{cli → lib/cli}/upload.js.map +1 -1
  58. package/{cli → lib/cli}/webpack.config.js +0 -0
  59. package/{context.d.ts → lib/context.d.ts} +0 -0
  60. package/{context.js → lib/context.js} +0 -0
  61. package/lib/context.js.map +1 -0
  62. package/{contract-namer.d.ts → lib/contract-namer.d.ts} +0 -0
  63. package/{contract-namer.js → lib/contract-namer.js} +0 -0
  64. package/{contract-namer.js.map → lib/contract-namer.js.map} +1 -1
  65. package/{error.d.ts → lib/error.d.ts} +0 -0
  66. package/{error.js → lib/error.js} +0 -0
  67. package/lib/error.js.map +1 -0
  68. package/{gen → lib/gen}/builtin.d.ts +0 -0
  69. package/{gen → lib/gen}/builtin.js +0 -0
  70. package/lib/gen/builtin.js.map +1 -0
  71. package/{gen → lib/gen}/google/protobuf/empty.d.ts +0 -0
  72. package/{gen → lib/gen}/google/protobuf/empty.js +0 -0
  73. package/lib/gen/google/protobuf/empty.js.map +1 -0
  74. package/{gen → lib/gen}/processor/protos/processor.d.ts +0 -0
  75. package/{gen → lib/gen}/processor/protos/processor.js +0 -0
  76. package/lib/gen/processor/protos/processor.js.map +1 -0
  77. package/{generic-processor.d.ts → lib/generic-processor.d.ts} +0 -0
  78. package/{generic-processor.js → lib/generic-processor.js} +0 -0
  79. package/lib/generic-processor.js.map +1 -0
  80. package/{index.d.ts → lib/index.d.ts} +0 -0
  81. package/{index.js → lib/index.js} +0 -0
  82. package/lib/index.js.map +1 -0
  83. package/{meter.d.ts → lib/meter.d.ts} +0 -0
  84. package/{meter.js → lib/meter.js} +0 -0
  85. package/lib/meter.js.map +1 -0
  86. package/{numberish.d.ts → lib/numberish.d.ts} +0 -0
  87. package/{numberish.js → lib/numberish.js} +0 -0
  88. package/lib/numberish.js.map +1 -0
  89. package/{numberish.test.d.ts → lib/numberish.test.d.ts} +0 -0
  90. package/{numberish.test.js → lib/numberish.test.js} +0 -0
  91. package/{numberish.test.js.map → lib/numberish.test.js.map} +1 -1
  92. package/{processor-runner.d.ts → lib/processor-runner.d.ts} +0 -0
  93. package/{processor-runner.js → lib/processor-runner.js} +0 -0
  94. package/lib/processor-runner.js.map +1 -0
  95. package/{processor-state.d.ts → lib/processor-state.d.ts} +0 -0
  96. package/{processor-state.js → lib/processor-state.js} +0 -0
  97. package/lib/processor-state.js.map +1 -0
  98. package/{promise-or-void.d.ts → lib/promise-or-void.d.ts} +0 -0
  99. package/{promise-or-void.js → lib/promise-or-void.js} +0 -0
  100. package/lib/promise-or-void.js.map +1 -0
  101. package/{provider.d.ts → lib/provider.d.ts} +0 -0
  102. package/{provider.js → lib/provider.js} +1 -1
  103. package/lib/provider.js.map +1 -0
  104. package/{release.config.js → lib/release.config.js} +0 -0
  105. package/{service.d.ts → lib/service.d.ts} +0 -0
  106. package/{service.js → lib/service.js} +0 -0
  107. package/lib/service.js.map +1 -0
  108. package/{solana → lib/solana}/builtin/index.d.ts +0 -0
  109. package/{solana → lib/solana}/builtin/index.js +0 -0
  110. package/lib/solana/builtin/index.js.map +1 -0
  111. package/{solana → lib/solana}/builtin/spl-token-processor.d.ts +0 -0
  112. package/{solana → lib/solana}/builtin/spl-token-processor.js +0 -0
  113. package/lib/solana/builtin/spl-token-processor.js.map +1 -0
  114. package/{solana → lib/solana}/builtin/types.d.ts +0 -0
  115. package/{solana → lib/solana}/builtin/types.js +0 -0
  116. package/lib/solana/builtin/types.js.map +1 -0
  117. package/{solana → lib/solana}/builtin/wormhole-processor.d.ts +0 -0
  118. package/{solana → lib/solana}/builtin/wormhole-processor.js +0 -0
  119. package/lib/solana/builtin/wormhole-processor.js.map +1 -0
  120. package/{solana-processor.d.ts → lib/solana-processor.d.ts} +0 -0
  121. package/{solana-processor.js → lib/solana-processor.js} +0 -0
  122. package/lib/solana-processor.js.map +1 -0
  123. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.d.ts +0 -0
  124. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js +0 -0
  125. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js.map +0 -0
  126. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.d.ts +0 -0
  127. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js +0 -0
  128. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js.map +0 -0
  129. package/{test → lib/test}/codegen.test.d.ts +0 -0
  130. package/{test → lib/test}/codegen.test.js +4 -8
  131. package/lib/test/codegen.test.js.map +1 -0
  132. package/{test → lib/test}/erc20-template.d.ts +0 -0
  133. package/{test → lib/test}/erc20-template.js +0 -0
  134. package/lib/test/erc20-template.js.map +1 -0
  135. package/{test → lib/test}/erc20-template.test.d.ts +0 -0
  136. package/{test → lib/test}/erc20-template.test.js +0 -0
  137. package/{test → lib/test}/erc20-template.test.js.map +1 -1
  138. package/{test → lib/test}/erc20.d.ts +0 -0
  139. package/{test → lib/test}/erc20.js +0 -0
  140. package/lib/test/erc20.js.map +1 -0
  141. package/{test → lib/test}/erc20.test.d.ts +0 -0
  142. package/{test → lib/test}/erc20.test.js +0 -0
  143. package/{test → lib/test}/erc20.test.js.map +1 -1
  144. package/{test → lib/test}/generic-processor.test.d.ts +0 -0
  145. package/{test → lib/test}/generic-processor.test.js +11 -1
  146. package/lib/test/generic-processor.test.js.map +1 -0
  147. package/{test → lib/test}/index.d.ts +0 -0
  148. package/{test → lib/test}/index.js +0 -0
  149. package/{test → lib/test}/index.js.map +1 -1
  150. package/{test → lib/test}/metric-utils.d.ts +0 -0
  151. package/{test → lib/test}/metric-utils.js +0 -0
  152. package/lib/test/metric-utils.js.map +1 -0
  153. package/{test → lib/test}/mirrorworld.d.ts +0 -0
  154. package/{test → lib/test}/mirrorworld.js +0 -0
  155. package/{test → lib/test}/mirrorworld.js.map +1 -1
  156. package/{test → lib/test}/solana.test.d.ts +0 -0
  157. package/{test → lib/test}/solana.test.js +0 -0
  158. package/lib/test/solana.test.js.map +1 -0
  159. package/{test → lib/test}/test-processor-server.d.ts +0 -0
  160. package/{test → lib/test}/test-processor-server.js +0 -0
  161. package/lib/test/test-processor-server.js.map +1 -0
  162. package/{test → lib/test}/types/game_wallet.d.ts +0 -0
  163. package/{test → lib/test}/types/game_wallet.js +0 -0
  164. package/lib/test/types/game_wallet.js.map +1 -0
  165. package/{test → lib/test}/types/game_wallet_processor.d.ts +0 -0
  166. package/{test → lib/test}/types/game_wallet_processor.js +0 -0
  167. package/lib/test/types/game_wallet_processor.js.map +1 -0
  168. package/{test → lib/test}/wormhole-token-bridge.d.ts +0 -0
  169. package/{test → lib/test}/wormhole-token-bridge.js +0 -0
  170. package/lib/test/wormhole-token-bridge.js.map +1 -0
  171. package/{utils → lib/utils}/chainmap.d.ts +0 -0
  172. package/{utils → lib/utils}/chainmap.js +0 -0
  173. package/lib/utils/chainmap.js.map +1 -0
  174. package/{utils → lib/utils}/convert.d.ts +0 -0
  175. package/{utils → lib/utils}/convert.js +0 -0
  176. package/lib/utils/convert.js.map +1 -0
  177. package/{utils → lib/utils}/index.d.ts +0 -0
  178. package/{utils → lib/utils}/index.js +0 -0
  179. package/lib/utils/index.js.map +1 -0
  180. package/package.json +47 -6
  181. package/src/abis/erc20.json +198 -0
  182. package/src/base-processor-template.ts +92 -0
  183. package/src/base-processor.ts +128 -0
  184. package/src/bind-options.ts +41 -0
  185. package/src/binds.ts +73 -0
  186. package/src/builtin/erc20/index.ts +6 -0
  187. package/src/builtin/erc20/test-utils.ts +49 -0
  188. package/src/builtin/internal/Erc20.ts +356 -0
  189. package/src/builtin/internal/common.ts +46 -0
  190. package/src/builtin/internal/erc20_processor.ts +295 -0
  191. package/src/builtin/internal/factories/Erc20__factory.ts +216 -0
  192. package/src/builtin/internal/factories/index.ts +4 -0
  193. package/src/builtin/internal/index.ts +6 -0
  194. package/src/chain-config.ts +6 -0
  195. package/src/cli/build.ts +180 -0
  196. package/src/cli/cli.ts +217 -0
  197. package/src/cli/config.ts +43 -0
  198. package/src/cli/key.ts +43 -0
  199. package/src/cli/solana-code-gen.ts +16 -0
  200. package/src/cli/upload.ts +86 -0
  201. package/src/cli/webpack.config.js +42 -0
  202. package/src/context.ts +93 -0
  203. package/src/contract-namer.ts +17 -0
  204. package/src/error.ts +43 -0
  205. package/src/gen/builtin.ts +22 -0
  206. package/src/gen/google/protobuf/empty.ts +70 -0
  207. package/src/gen/processor/protos/processor.ts +3071 -0
  208. package/src/generic-processor.ts +38 -0
  209. package/src/index.ts +19 -0
  210. package/src/meter.ts +122 -0
  211. package/src/numberish.test.ts +82 -0
  212. package/src/numberish.ts +99 -0
  213. package/src/processor-runner.ts +75 -0
  214. package/src/processor-state.ts +24 -0
  215. package/src/promise-or-void.ts +1 -0
  216. package/src/provider.ts +74 -0
  217. package/src/service.ts +434 -0
  218. package/src/solana/builtin/index.ts +2 -0
  219. package/src/solana/builtin/spl-token-processor.ts +164 -0
  220. package/src/solana/builtin/types.ts +268 -0
  221. package/src/solana/builtin/wormhole-processor.ts +178 -0
  222. package/src/solana-processor.ts +105 -0
  223. package/src/target-ethers-sentio/codegen.ts +289 -0
  224. package/src/target-ethers-sentio/index.ts +50 -0
  225. package/src/target-ethers-sentio/tsconfig.json +9 -0
  226. package/src/test/abis/evm/anyswapRouter.json +490 -0
  227. package/src/test/abis/solana/mirrorworld.json +1392 -0
  228. package/src/test/codegen.test.ts +26 -0
  229. package/src/test/erc20-template.test.ts +39 -0
  230. package/src/test/erc20-template.ts +25 -0
  231. package/src/test/erc20.test.ts +92 -0
  232. package/src/test/erc20.ts +48 -0
  233. package/src/test/generic-processor.test.ts +72 -0
  234. package/src/test/index.ts +1 -0
  235. package/src/test/metric-utils.ts +49 -0
  236. package/src/test/mirrorworld.ts +40 -0
  237. package/src/test/sentio.yaml +4 -0
  238. package/src/test/solana.test.ts +93 -0
  239. package/src/test/test-processor-server.ts +210 -0
  240. package/src/test/types/game_wallet.ts +1392 -0
  241. package/src/test/types/game_wallet_processor.ts +113 -0
  242. package/src/test/wormhole-token-bridge.ts +21 -0
  243. package/src/types/global.d.ts +17 -0
  244. package/src/utils/chainmap.ts +95 -0
  245. package/src/utils/convert.ts +6 -0
  246. package/src/utils/index.ts +2 -0
  247. package/base-processor-template.js.map +0 -1
  248. package/base-processor.js.map +0 -1
  249. package/bind-options.js.map +0 -1
  250. package/binds.js.map +0 -1
  251. package/builtin/erc20/index.js.map +0 -1
  252. package/builtin/erc20/test-utils.js.map +0 -1
  253. package/builtin/internal/Erc20.js.map +0 -1
  254. package/builtin/internal/common.js.map +0 -1
  255. package/builtin/internal/erc20_processor.js.map +0 -1
  256. package/builtin/internal/factories/Erc20__factory.js.map +0 -1
  257. package/builtin/internal/index.js.map +0 -1
  258. package/chain-config.js.map +0 -1
  259. package/cli/build.js.map +0 -1
  260. package/cli/cli.js.map +0 -1
  261. package/cli/config.js.map +0 -1
  262. package/context.js.map +0 -1
  263. package/error.js.map +0 -1
  264. package/gen/builtin.js.map +0 -1
  265. package/gen/google/protobuf/empty.js.map +0 -1
  266. package/gen/processor/protos/processor.js.map +0 -1
  267. package/generic-processor.js.map +0 -1
  268. package/index.js.map +0 -1
  269. package/meter.js.map +0 -1
  270. package/numberish.js.map +0 -1
  271. package/processor-runner.js.map +0 -1
  272. package/processor-state.js.map +0 -1
  273. package/promise-or-void.js.map +0 -1
  274. package/provider.js.map +0 -1
  275. package/service.js.map +0 -1
  276. package/solana/builtin/index.js.map +0 -1
  277. package/solana/builtin/spl-token-processor.js.map +0 -1
  278. package/solana/builtin/types.js.map +0 -1
  279. package/solana/builtin/wormhole-processor.js.map +0 -1
  280. package/solana-processor.js.map +0 -1
  281. package/test/codegen.test.js.map +0 -1
  282. package/test/erc20-template.js.map +0 -1
  283. package/test/erc20.js.map +0 -1
  284. package/test/generic-processor.test.js.map +0 -1
  285. package/test/metric-utils.js.map +0 -1
  286. package/test/solana.test.js.map +0 -1
  287. package/test/test-processor-server.js.map +0 -1
  288. package/test/types/game_wallet.js.map +0 -1
  289. package/test/types/game_wallet_processor.js.map +0 -1
  290. package/test/wormhole-token-bridge.js.map +0 -1
  291. package/utils/chainmap.js.map +0 -1
  292. package/utils/convert.js.map +0 -1
  293. package/utils/index.js.map +0 -1
@@ -0,0 +1,26 @@
1
+ import { codeGenEthersProcessor } from '../cli/build'
2
+ import path from 'path'
3
+ import * as fs from 'fs'
4
+ import os from 'os'
5
+
6
+ describe('Test EVM codegen', () => {
7
+ const codeGenFolder = fs.mkdtempSync(path.join(os.tmpdir(), 'codegen_test'))
8
+
9
+ jest.setTimeout(20000)
10
+
11
+ test('code gen for anyswapRouter', async () => {
12
+ await codeGenEthersProcessor(
13
+ path.join(__dirname, 'abis/evm'),
14
+ 'lib/target-ethers-sentio',
15
+ `${codeGenFolder}/internal`
16
+ )
17
+ expect(fs.existsSync(codeGenFolder)).toEqual(true)
18
+ expect(fs.readdirSync(codeGenFolder).length).toEqual(2)
19
+ })
20
+
21
+ afterAll(() => {
22
+ if (fs.existsSync(codeGenFolder)) {
23
+ fs.rmSync(codeGenFolder, { recursive: true, force: true })
24
+ }
25
+ })
26
+ })
@@ -0,0 +1,39 @@
1
+ // TODO move out of this package
2
+
3
+ import { expect } from 'chai'
4
+
5
+ import { StartRequest } from '..'
6
+ import Long from 'long'
7
+ import { TestProcessorServer } from './test-processor-server'
8
+
9
+ describe('Test Template', () => {
10
+ const service = new TestProcessorServer()
11
+
12
+ beforeAll(async () => {
13
+ service.setup()
14
+ require('./erc20-template')
15
+ const request: StartRequest = {
16
+ templateInstances: [
17
+ {
18
+ contract: {
19
+ address: 'dynamic2',
20
+ name: 'dynamic2',
21
+ chainId: '1',
22
+ abi: '',
23
+ },
24
+ startBlock: Long.ZERO,
25
+ endBlock: Long.ZERO,
26
+ templateId: 0,
27
+ },
28
+ ],
29
+ }
30
+ await service.start(request)
31
+ })
32
+
33
+ test('Check template instantiate', async () => {
34
+ const config = await service.getConfig({})
35
+ expect(config.contractConfigs).length(2)
36
+ expect(config.contractConfigs?.[1].contract?.name).equals('dynamic2')
37
+ expect(config.templateInstances).length(1)
38
+ })
39
+ })
@@ -0,0 +1,25 @@
1
+ import { Erc20Processor, Erc20ProcessorTemplate } from '../builtin/erc20'
2
+
3
+ export const filter = Erc20Processor.filters.Transfer(
4
+ '0x0000000000000000000000000000000000000000',
5
+ '0xb329e39ebefd16f40d38f07643652ce17ca5bac1'
6
+ )
7
+
8
+ const processorTemplate = new Erc20ProcessorTemplate().onTransfer(async function (event, ctx) {
9
+ console.log('')
10
+ })
11
+
12
+ Erc20Processor.bind({
13
+ address: '0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9',
14
+ network: 1,
15
+ name: 'x2y2',
16
+ startBlock: 14201940,
17
+ }).onTransfer(async function (event, ctx) {
18
+ processorTemplate.bind({
19
+ address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
20
+ network: 3,
21
+ name: 'dynamic',
22
+ })
23
+ // template.bind('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 3, 'dynamic')
24
+ ctx.meter.Counter('c1').add(1)
25
+ }, filter)
@@ -0,0 +1,92 @@
1
+ // TODO move out of this package
2
+
3
+ import { expect } from 'chai'
4
+
5
+ import { HandlerType } from '..'
6
+
7
+ import { TestProcessorServer } from './test-processor-server'
8
+ import { firstCounterValue, firstGaugeValue } from './metric-utils'
9
+ import { BigNumber } from 'ethers'
10
+ import { mockTransferLog } from '../builtin/erc20/test-utils'
11
+
12
+ describe('Test Basic Examples', () => {
13
+ const service = new TestProcessorServer()
14
+
15
+ beforeAll(async () => {
16
+ service.setup()
17
+ require('./erc20')
18
+ await service.start()
19
+ })
20
+
21
+ test('check configuration', async () => {
22
+ const config = await service.getConfig({})
23
+ expect(config.contractConfigs).length(5)
24
+
25
+ // check auto rename
26
+ expect(config.contractConfigs?.[2].contract?.name).equals('Erc20')
27
+ expect(config.contractConfigs?.[3].contract?.name).equals('Erc20_1')
28
+ // same as above because only differ in parameters
29
+ expect(config.contractConfigs?.[4].contract?.name).equals('Erc20_1')
30
+ })
31
+
32
+ test('Check block dispatch', async () => {
33
+ const res = await service.testBlock(blockData)
34
+ const o11yRes = res.result
35
+ expect(o11yRes?.counters).length(0)
36
+ expect(o11yRes?.gauges).length(1)
37
+ expect(firstGaugeValue(o11yRes, 'g1')).equals(10n)
38
+
39
+ const gauge = o11yRes?.gauges?.[0]
40
+ expect(gauge?.metadata?.blockNumber?.toString()).equals('14373295')
41
+ expect(gauge?.runtimeInfo?.from).equals(HandlerType.BLOCK)
42
+
43
+ const res2 = await service.testBlock(blockData, 56)
44
+ const o11yRes2 = res2.result
45
+ expect(o11yRes2?.counters).length(0)
46
+ expect(o11yRes2?.gauges).length(1)
47
+ expect(firstGaugeValue(o11yRes2, 'g2')).equals(20n)
48
+ })
49
+
50
+ test('Check log dispatch', async () => {
51
+ const logData = mockTransferLog('0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9', {
52
+ from: '0x0000000000000000000000000000000000000000',
53
+ to: '0xB329e39Ebefd16f40d38f07643652cE17Ca5Bac1',
54
+ value: BigNumber.from('0x9a71db64810aaa0000'),
55
+ })
56
+
57
+ let res = await service.testLog(logData)
58
+
59
+ const counters = res.result?.counters
60
+ expect(counters).length(1)
61
+ expect(firstCounterValue(res.result, 'c1')).equals(1n)
62
+
63
+ expect(counters?.[0].metadata?.chainId).equals('1')
64
+ expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.LOG)
65
+ expect(res.configUpdated).equals(true)
66
+
67
+ const logData2 = Object.assign({}, logData)
68
+ logData2.address = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
69
+ res = await service.testLog(logData2, 56)
70
+
71
+ expect(firstCounterValue(res.result, 'c2')).equals(2n)
72
+ expect(res.result?.counters[0].metadata?.chainId).equals('56')
73
+
74
+ expect(res.result?.gauges).length(0)
75
+
76
+ const config = await service.getConfig({})
77
+ expect(config.contractConfigs).length(6) //config increased
78
+ expect(config.contractConfigs?.[5].contract?.name).equals('dynamic')
79
+
80
+ // repeat trigger won't bind again
81
+ await service.testLogs([logData])
82
+ const config2 = await service.getConfig({})
83
+ expect(config).deep.equals(config2)
84
+ })
85
+
86
+ const blockData = {
87
+ hash: '0x2b9b7cce1f17f3b7e1f3c2472cc806a07bee3f0baca07d021350950d81d73a42',
88
+ number: 14373295,
89
+ timestamp: 1647106437,
90
+ extraData: '0xe4b883e5bda9e7a59ee4bb99e9b1bc493421',
91
+ }
92
+ })
@@ -0,0 +1,48 @@
1
+ import { Erc20Processor, Erc20ProcessorTemplate } from '../builtin/erc20'
2
+
3
+ export const filter = Erc20Processor.filters.Transfer(
4
+ '0x0000000000000000000000000000000000000000',
5
+ '0xb329e39ebefd16f40d38f07643652ce17ca5bac1'
6
+ )
7
+
8
+ const processorTemplate = new Erc20ProcessorTemplate().onTransfer(async function (event, ctx) {
9
+ console.log('')
10
+ })
11
+
12
+ Erc20Processor.bind({
13
+ address: '0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9',
14
+ // network: 1,
15
+ name: 'x2y2',
16
+ startBlock: 14201940,
17
+ })
18
+ .onTransfer(async function (event, ctx) {
19
+ processorTemplate.bind({ address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9', network: 3, name: 'dynamic' })
20
+ // template.bind('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 3, 'dynamic')
21
+ ctx.meter.Counter('c1').add(1)
22
+ }, filter)
23
+ .onBlock(async function (block, ctx) {
24
+ ctx.meter.Gauge('g1').record(10, { k: 'v' })
25
+ })
26
+
27
+ Erc20Processor.bind({ address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', network: 56, name: 'usdc' })
28
+ .onTransfer(async function (event, ctx) {
29
+ ctx.meter.Counter('c2').add(2)
30
+ }, filter)
31
+ .onBlock(async function (block, ctx) {
32
+ ctx.meter.Gauge('g2').record(20, { k: 'v' })
33
+ })
34
+ // .startBlock(14201940)
35
+
36
+ Erc20Processor.bind({ address: 'xxxx', network: 56 })
37
+
38
+ Erc20Processor.bind({ address: 'yyyy', network: 1 })
39
+ Erc20Processor.bind({ address: 'yyyy', network: 1 })
40
+ Erc20Processor.bind({ address: 'yyyy', network: 1, startBlock: 21 })
41
+
42
+ // const template = Erc20Processor.template
43
+ // .onTransfer(async function (event, ctx) {
44
+ // ctx.meter.Counter('c2').add(2)
45
+ // }, filter)
46
+ // .onBlock(async function (block, ctx) {
47
+ // ctx.meter.Gauge('h1').record(20, { k: 'v' })
48
+ // })
@@ -0,0 +1,72 @@
1
+ // TODO move out of this package
2
+
3
+ import { expect } from 'chai'
4
+
5
+ import { HandlerType } from '..'
6
+
7
+ import { GenericProcessor } from '../generic-processor'
8
+ import { TestProcessorServer } from './test-processor-server'
9
+ import { firstCounterValue } from './metric-utils'
10
+
11
+ describe('Test Generic Processor', () => {
12
+ const service = new TestProcessorServer()
13
+
14
+ beforeAll(async () => {
15
+ service.setup()
16
+
17
+ GenericProcessor.bind(
18
+ [
19
+ 'event Transfer(address indexed from, address indexed to, uint256 value)',
20
+ 'event Approval(address indexed from, address indexed to, uint256 value)',
21
+ ],
22
+ { address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9' }
23
+ ).onAllEvents(function (log, ctx) {
24
+ ctx.meter.Counter('event_num').add(1)
25
+ })
26
+
27
+ GenericProcessor.bind('event WalletCreated(address wallet, address owner)', {
28
+ address: '0x57E037F4d2c8BEa011Ad8a9A5AF4AaEEd508650f',
29
+ }).onAllEvents(function (log, ctx) {
30
+ ctx.meter.Counter('wallet').add(1)
31
+ })
32
+
33
+ await service.start()
34
+ })
35
+
36
+ test('check configuration', async () => {
37
+ const config = await service.getConfig({})
38
+ expect(config.contractConfigs).length(2)
39
+ expect(config.contractConfigs?.[0].contract?.name).equals('Generic')
40
+ })
41
+
42
+ test('Check log dispatch', async () => {
43
+ const res = await service.testLogs([logData, logData])
44
+ const counters = res.result?.counters
45
+ expect(counters).length(2)
46
+ expect(firstCounterValue(res.result, 'event_num')).equals(1n)
47
+ expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.LOG)
48
+ })
49
+
50
+ test('Check log dispatch no buffer over rune', async () => {
51
+ const logStr =
52
+ '{"address":"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f","topics":["0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081"],"data":"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24","blockNumber":"0xc9d6d7","transactionHash":"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2","transactionIndex":"0xf3","blockHash":"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6","logIndex":"0x14b","removed":false}'
53
+ const res = await service.testLog(JSON.parse(logStr))
54
+ console.log(JSON.stringify(res))
55
+ })
56
+
57
+ const logData = {
58
+ blockNumber: 14213252,
59
+ blockHash: '0x83d646fac9350b281def8c4c37626f9d8efc95df801287b848c719edf35cdbaf',
60
+ transactionIndex: 347,
61
+ removed: false,
62
+ address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9',
63
+ data: '0x00000000000000000000000000000000000000000000009a71db64810aaa0000',
64
+ topics: [
65
+ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
66
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
67
+ '0x000000000000000000000000b329e39ebefd16f40d38f07643652ce17ca5bac1',
68
+ ],
69
+ transactionHash: '0x93355e0cb2c3490cb8a747029ff2dc8cdbde2407025b8391398436955afae303',
70
+ logIndex: 428,
71
+ }
72
+ })
@@ -0,0 +1 @@
1
+ export { TestProcessorServer } from './test-processor-server'
@@ -0,0 +1,49 @@
1
+ import { DeepPartial } from '../gen/builtin'
2
+ import { BigDecimal, MetricValue, O11yResult } from '@sentio/sdk'
3
+ import { Numberish } from '../numberish'
4
+ import { BigNumber } from 'ethers'
5
+
6
+ export function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Numberish | undefined {
7
+ if (v === undefined) {
8
+ return undefined
9
+ }
10
+
11
+ if (v.doubleValue !== undefined) {
12
+ return v.doubleValue
13
+ }
14
+ if (v.bigInteger !== undefined) {
15
+ let intValue = BigNumber.from(v.bigInteger.data).toBigInt()
16
+ if (v.bigInteger.negative) {
17
+ intValue = -intValue
18
+ }
19
+ return intValue
20
+ }
21
+ if (v.bigDecimal !== undefined) {
22
+ return new BigDecimal(v.bigDecimal)
23
+ }
24
+ return undefined
25
+ }
26
+
27
+ export function firstCounterValue(result: O11yResult | undefined, name: string): Numberish | undefined {
28
+ if (!result) {
29
+ return undefined
30
+ }
31
+ for (const counter of result.counters) {
32
+ if (counter.metadata?.name === name) {
33
+ return MetricValueToNumber(counter.metricValue)
34
+ }
35
+ }
36
+ return undefined
37
+ }
38
+
39
+ export function firstGaugeValue(result: O11yResult | undefined, name: string): Numberish | undefined {
40
+ if (!result) {
41
+ return undefined
42
+ }
43
+ for (const gauge of result.gauges) {
44
+ if (gauge.metadata?.name === name) {
45
+ return MetricValueToNumber(gauge.metricValue)
46
+ }
47
+ }
48
+ return undefined
49
+ }
@@ -0,0 +1,40 @@
1
+ import { GameWalletProcessor } from './types/game_wallet_processor'
2
+
3
+ GameWalletProcessor.bind({ address: 'F78NhTC9XmP1DKsCBRz5LGdQc4n4yFbj2dURiv7T9gGZ' })
4
+ .onDistributeWithoutUser((payload, ctx) => {
5
+ const amount = payload.amount.toNumber()
6
+ ctx.meter.Counter('deposit_pool_total_value').add(amount)
7
+ ctx.meter.Counter('deposit_pool_current_value').add(amount)
8
+ ctx.meter.Counter('distribution_pool_total_value').sub(amount)
9
+ })
10
+ .onDeposit((payload, ctx) => {
11
+ const amount = payload.amount.toNumber()
12
+ ctx.meter.Counter('deposit_pool_total_value').add(amount)
13
+ ctx.meter.Counter('deposit_pool_current_value').add(amount)
14
+ })
15
+ .onWithdraw((payload, ctx) => {
16
+ const amount = payload.amount.toNumber()
17
+ ctx.meter.Counter('deposit_pool_total_value').add(amount)
18
+ ctx.meter.Counter('distribution_pool_total_value').sub(amount)
19
+ })
20
+ .onSpend((payload, ctx) => {
21
+ const amount = payload.amount.toNumber()
22
+ ctx.meter.Counter('deposit_pool_total_value').add(amount)
23
+ ctx.meter.Counter('distribution_pool_total_value').sub(amount)
24
+ })
25
+ .onDistribute((payload, ctx) => {
26
+ const amount = payload.amount.toNumber()
27
+ ctx.meter.Counter('deposit_pool_total_value').add(amount)
28
+ ctx.meter.Counter('deposit_pool_current_value').add(amount)
29
+ ctx.meter.Counter('distribution_pool_total_value').sub(amount)
30
+ })
31
+ .onSpendWithoutUser((payload, ctx) => {
32
+ const amount = payload.amount.toNumber()
33
+ ctx.meter.Counter('deposit_pool_total_value').add(amount)
34
+ ctx.meter.Counter('deposit_pool_current_value').sub(amount)
35
+ })
36
+ .onAddDistributeSupply((payload, ctx) => {
37
+ const amount = payload.amount.toNumber()
38
+ ctx.meter.Counter('distribution_pool_total_value').add(amount)
39
+ })
40
+ .startSlot(142700000)
@@ -0,0 +1,4 @@
1
+ project: test
2
+ # project: user_org_name/name
3
+ host: test # local/test/staging/prod
4
+ definition: src/
@@ -0,0 +1,93 @@
1
+ // TODO move out of this package
2
+
3
+ import { expect } from 'chai'
4
+
5
+ import { HandlerType, ProcessInstructionsRequest } from '..'
6
+
7
+ import Long from 'long'
8
+ import { TextEncoder } from 'util'
9
+ import { TestProcessorServer } from './test-processor-server'
10
+ import { firstCounterValue } from './metric-utils'
11
+
12
+ describe('Test Solana Example', () => {
13
+ const service = new TestProcessorServer()
14
+
15
+ beforeAll(async () => {
16
+ await service.setup()
17
+ require('./mirrorworld')
18
+ require('./wormhole-token-bridge')
19
+ await service.start({ templateInstances: [] })
20
+ })
21
+
22
+ test('check configuration ', async () => {
23
+ const config = await service.getConfig({})
24
+ expect(config.contractConfigs).length(3)
25
+ })
26
+
27
+ test('Check mirrorworld instruction dispatch', async () => {
28
+ const request: ProcessInstructionsRequest = {
29
+ instructions: [
30
+ {
31
+ instructionData: 'CACadoFwjNvan4GP8gh3Jtm1qdeoKX5j2SbSNEiB',
32
+ slot: Long.fromNumber(0),
33
+ programAccountId: 'F78NhTC9XmP1DKsCBRz5LGdQc4n4yFbj2dURiv7T9gGZ',
34
+ },
35
+ ],
36
+ }
37
+ const res = await service.processInstructions(request)
38
+ expect(res.result?.counters).length(3)
39
+ expect(res.result?.gauges).length(0)
40
+ expect(firstCounterValue(res.result, 'deposit_pool_total_value')).equal(5000000000n)
41
+ })
42
+
43
+ test('Check wormhole token bridge instruction dispatch', async () => {
44
+ const request: ProcessInstructionsRequest = {
45
+ instructions: [
46
+ {
47
+ instructionData: '33G5T8yXAQWdH8FX7fTy1mBJ6e4dUKfQWbViSrT7qJjpS8UAA3ftEQx9sNzrkaJm56xtENhDsWf',
48
+ slot: Long.fromNumber(0),
49
+ programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
50
+ },
51
+ {
52
+ instructionData: '33G5T8yXAQWdH8FX7fTy1mBJ6e4dUKfQWbViSrT7qJjpS8UAA3ftEQx9sNzrkaJm56xtENhDsWf',
53
+ slot: Long.fromNumber(1),
54
+ programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
55
+ },
56
+ ],
57
+ }
58
+ const res = await service.processInstructions(request)
59
+ expect(res.result?.counters).length(2)
60
+ expect(res.result?.gauges).length(0)
61
+ expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(0)
62
+ expect(firstCounterValue(res.result, 'total_transfer_amount')).equal(1000000n)
63
+ expect(res.result?.counters[0].runtimeInfo?.from).equals(HandlerType.INSTRUCTION)
64
+ })
65
+
66
+ test('Check SPLToken parsed instruction dispatch', async () => {
67
+ const parsedIns = {
68
+ info: {
69
+ account: '2SDN4vEJdCdW3pGyhx2km9gB3LeHzMGLrG2j4uVNZfrx',
70
+ amount: '12000000000000',
71
+ mint: '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs',
72
+ mintAuthority: 'BCD75RNBHrJJpW4dXVagL5mPjzRLnVZq4YirJdjEYMV7',
73
+ },
74
+ type: 'mintTo',
75
+ }
76
+ const request: ProcessInstructionsRequest = {
77
+ instructions: [
78
+ {
79
+ instructionData: '',
80
+ slot: Long.fromNumber(0),
81
+ programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
82
+ parsed: new TextEncoder().encode(JSON.stringify(parsedIns)),
83
+ },
84
+ ],
85
+ }
86
+ const res = await service.processInstructions(request)
87
+ expect(res.result?.counters).length(1)
88
+ expect(res.result?.gauges).length(0)
89
+ expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(0)
90
+ expect(firstCounterValue(res.result, 'totalWeth_supply')).equal(12000000000000)
91
+ expect(res.result?.counters[0].runtimeInfo?.from).equals(HandlerType.INSTRUCTION)
92
+ })
93
+ })