@sentio/sdk 1.17.2 → 1.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/binds.d.ts +2 -3
- package/lib/binds.js +1 -1
- package/lib/binds.js.map +1 -1
- package/lib/builtin/eacaggregatorproxy/test-utils.js +4 -4
- package/lib/builtin/eacaggregatorproxy/test-utils.js.map +1 -1
- package/lib/builtin/erc20/test-utils.js +3 -3
- package/lib/builtin/erc20/test-utils.js.map +1 -1
- package/lib/builtin/erc20bytes/test-utils.js +2 -2
- package/lib/builtin/erc20bytes/test-utils.js.map +1 -1
- package/lib/builtin/index.d.ts +5 -0
- package/lib/builtin/index.js +32 -0
- package/lib/builtin/index.js.map +1 -0
- package/lib/{solana/builtin → builtin/solana}/index.d.ts +0 -0
- package/lib/{solana/builtin → builtin/solana}/index.js +0 -0
- package/lib/{solana/builtin → builtin/solana}/index.js.map +1 -1
- package/lib/{solana/builtin → builtin/solana}/spl-token-processor.d.ts +1 -3
- package/lib/{solana/builtin → builtin/solana}/spl-token-processor.js +2 -2
- package/lib/builtin/solana/spl-token-processor.js.map +1 -0
- package/lib/{solana/builtin → builtin/solana}/types.d.ts +27 -27
- package/lib/{solana/builtin → builtin/solana}/types.js +0 -0
- package/lib/{solana/builtin → builtin/solana}/types.js.map +1 -1
- package/lib/{solana/builtin → builtin/solana}/wormhole-processor.d.ts +1 -3
- package/lib/{solana/builtin → builtin/solana}/wormhole-processor.js +2 -2
- package/lib/builtin/solana/wormhole-processor.js.map +1 -0
- package/lib/builtin/weth9/test-utils.js +4 -4
- package/lib/builtin/weth9/test-utils.js.map +1 -1
- package/lib/cli/webpack.config.js +1 -1
- package/lib/{aptos-processor.d.ts → core/aptos-processor.d.ts} +3 -2
- package/lib/{aptos-processor.js → core/aptos-processor.js} +4 -2
- package/lib/core/aptos-processor.js.map +1 -0
- package/lib/{base-processor-template.d.ts → core/base-processor-template.d.ts} +1 -1
- package/lib/{base-processor-template.js → core/base-processor-template.js} +0 -0
- package/lib/core/base-processor-template.js.map +1 -0
- package/lib/{base-processor.d.ts → core/base-processor.d.ts} +2 -2
- package/lib/{base-processor.js → core/base-processor.js} +0 -0
- package/lib/core/base-processor.js.map +1 -0
- package/lib/{bind-options.d.ts → core/bind-options.d.ts} +0 -0
- package/lib/{bind-options.js → core/bind-options.js} +0 -0
- package/lib/core/bind-options.js.map +1 -0
- package/lib/{context.d.ts → core/context.d.ts} +7 -4
- package/lib/{context.js → core/context.js} +12 -6
- package/lib/core/context.js.map +1 -0
- package/lib/{generic-processor.d.ts → core/generic-processor.d.ts} +0 -0
- package/lib/{generic-processor.js → core/generic-processor.js} +2 -2
- package/lib/core/generic-processor.js.map +1 -0
- package/lib/{test → core}/generic-processor.test.d.ts +0 -0
- package/lib/{test → core}/generic-processor.test.js +4 -5
- package/lib/core/generic-processor.test.js.map +1 -0
- package/lib/core/index.d.ts +12 -0
- package/lib/core/index.js +38 -0
- package/lib/core/index.js.map +1 -0
- package/lib/{meter.d.ts → core/meter.d.ts} +1 -1
- package/lib/{meter.js → core/meter.js} +11 -14
- package/lib/core/meter.js.map +1 -0
- package/lib/{meter.test.d.ts → core/meter.test.d.ts} +0 -0
- package/lib/{meter.test.js → core/meter.test.js} +0 -0
- package/lib/core/meter.test.js.map +1 -0
- package/lib/{numberish.d.ts → core/numberish.d.ts} +1 -1
- package/lib/{numberish.js → core/numberish.js} +1 -1
- package/lib/core/numberish.js.map +1 -0
- package/lib/{numberish.test.d.ts → core/numberish.test.d.ts} +0 -0
- package/lib/{numberish.test.js → core/numberish.test.js} +4 -4
- package/lib/core/numberish.test.js.map +1 -0
- package/lib/{solana-processor.d.ts → core/solana-processor.d.ts} +2 -2
- package/lib/{solana-processor.js → core/solana-processor.js} +2 -2
- package/lib/core/solana-processor.js.map +1 -0
- package/lib/{sui-processor.d.ts → core/sui-processor.d.ts} +2 -2
- package/lib/{sui-processor.js → core/sui-processor.js} +2 -2
- package/lib/core/sui-processor.js.map +1 -0
- package/lib/{trace.d.ts → core/trace.d.ts} +0 -0
- package/lib/{trace.js → core/trace.js} +0 -0
- package/lib/core/trace.js.map +1 -0
- package/lib/error.d.ts +1 -1
- package/lib/error.js.map +1 -1
- package/lib/index.d.ts +1 -12
- package/lib/index.js +2 -34
- package/lib/index.js.map +1 -1
- package/lib/processor-state.d.ts +1 -6
- package/lib/processor-state.js.map +1 -1
- package/lib/service.js +21 -54
- package/lib/service.js.map +1 -1
- package/lib/target-ethers-sentio/codegen.js +2 -1
- package/lib/target-ethers-sentio/codegen.js.map +1 -1
- package/lib/{test → testing}/index.d.ts +0 -1
- package/lib/{test → testing}/index.js +2 -3
- package/lib/testing/index.js.map +1 -0
- package/lib/{test → testing}/metric-utils.d.ts +1 -1
- package/lib/{test → testing}/metric-utils.js +0 -0
- package/lib/testing/metric-utils.js.map +1 -0
- package/lib/{test → testing}/test-processor-server.d.ts +1 -1
- package/lib/{test → testing}/test-processor-server.js +2 -2
- package/lib/testing/test-processor-server.js.map +1 -0
- package/lib/{test → testing}/test-provider.d.ts +0 -0
- package/lib/{test → testing}/test-provider.js +5 -3
- package/lib/testing/test-provider.js.map +1 -0
- package/lib/{test → tests}/aptos.test.d.ts +0 -0
- package/lib/{test → tests}/aptos.test.js +10 -3
- package/lib/tests/aptos.test.js.map +1 -0
- package/lib/{test → tests}/codegen.test.d.ts +0 -0
- package/lib/{test → tests}/codegen.test.js +0 -0
- package/lib/tests/codegen.test.js.map +1 -0
- package/lib/{test → tests}/erc20-template.test.d.ts +0 -0
- package/lib/{test → tests}/erc20-template.test.js +2 -2
- package/lib/tests/erc20-template.test.js.map +1 -0
- package/lib/{test → tests}/erc20.d.ts +0 -0
- package/lib/{test → tests}/erc20.js +0 -0
- package/lib/tests/erc20.js.map +1 -0
- package/lib/{test → tests}/erc20.test.d.ts +0 -0
- package/lib/{test → tests}/erc20.test.js +6 -7
- package/lib/tests/erc20.test.js.map +1 -0
- package/lib/{test → tests}/error-capture.test.d.ts +0 -0
- package/lib/{test → tests}/error-capture.test.js +4 -4
- package/lib/tests/error-capture.test.js.map +1 -0
- package/lib/{test → tests}/solana.test.d.ts +0 -0
- package/lib/{test → tests}/solana.test.js +6 -7
- package/lib/tests/solana.test.js.map +1 -0
- package/lib/{test → tests}/souffl3.d.ts +0 -0
- package/lib/{test → tests}/souffl3.js +2 -2
- package/lib/tests/souffl3.js.map +1 -0
- package/lib/{test → tests}/sui.test.d.ts +0 -0
- package/lib/{test → tests}/sui.test.js +10 -4
- package/lib/tests/sui.test.js.map +1 -0
- package/lib/{test → tests}/types/basic_1.d.ts +0 -0
- package/lib/{test → tests}/types/basic_1.js +0 -0
- package/lib/tests/types/basic_1.js.map +1 -0
- package/lib/{test → tests}/types/basic_1_processor.d.ts +0 -0
- package/lib/{test → tests}/types/basic_1_processor.js +0 -0
- package/lib/tests/types/basic_1_processor.js.map +1 -0
- package/lib/{test → tests}/wormhole-token-bridge.d.ts +0 -0
- package/lib/{test → tests}/wormhole-token-bridge.js +3 -4
- package/lib/tests/wormhole-token-bridge.js.map +1 -0
- package/lib/utils/chain.d.ts +7 -0
- package/lib/utils/{chainmap.js → chain.js} +12 -5
- package/lib/utils/chain.js.map +1 -0
- package/lib/utils/{convert.d.ts → conversion.d.ts} +1 -1
- package/lib/utils/{convert.js → conversion.js} +1 -1
- package/lib/utils/conversion.js.map +1 -0
- package/lib/utils/dex-price.d.ts +5 -5
- package/lib/utils/dex-price.js +2 -2
- package/lib/utils/dex-price.js.map +1 -1
- package/lib/utils/dex-price.test.js +2 -2
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.js +6 -5
- package/lib/utils/erc20.test.js.map +1 -1
- package/lib/utils/index.d.ts +4 -5
- package/lib/utils/index.js +28 -16
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/{erc20.d.ts → token.d.ts} +1 -1
- package/lib/utils/{erc20.js → token.js} +4 -10
- package/lib/utils/token.js.map +1 -0
- package/package.json +5 -3
- package/src/binds.ts +2 -3
- package/src/builtin/eacaggregatorproxy/test-utils.ts +4 -4
- package/src/builtin/erc20/test-utils.ts +3 -3
- package/src/builtin/erc20bytes/test-utils.ts +2 -2
- package/src/builtin/index.ts +5 -0
- package/src/{solana/builtin → builtin/solana}/index.ts +0 -0
- package/src/{solana/builtin → builtin/solana}/spl-token-processor.ts +1 -3
- package/src/{solana/builtin → builtin/solana}/types.ts +0 -0
- package/src/{solana/builtin → builtin/solana}/wormhole-processor.ts +1 -3
- package/src/builtin/weth9/test-utils.ts +4 -4
- package/src/cli/webpack.config.js +1 -1
- package/src/{aptos-processor.ts → core/aptos-processor.ts} +5 -3
- package/src/{base-processor-template.ts → core/base-processor-template.ts} +2 -2
- package/src/{base-processor.ts → core/base-processor.ts} +2 -2
- package/src/{bind-options.ts → core/bind-options.ts} +0 -0
- package/src/{context.ts → core/context.ts} +13 -7
- package/src/{test → core}/generic-processor.test.ts +2 -3
- package/src/{generic-processor.ts → core/generic-processor.ts} +2 -2
- package/src/core/index.ts +15 -0
- package/src/{meter.test.ts → core/meter.test.ts} +0 -0
- package/src/{meter.ts → core/meter.ts} +11 -11
- package/src/{numberish.test.ts → core/numberish.test.ts} +2 -2
- package/src/{numberish.ts → core/numberish.ts} +1 -1
- package/src/{solana-processor.ts → core/solana-processor.ts} +3 -3
- package/src/{sui-processor.ts → core/sui-processor.ts} +3 -3
- package/src/{trace.ts → core/trace.ts} +0 -0
- package/src/error.ts +1 -1
- package/src/index.ts +1 -13
- package/src/processor-state.ts +9 -6
- package/src/service.ts +32 -54
- package/src/target-ethers-sentio/codegen.ts +3 -1
- package/src/{test → testing}/index.ts +2 -1
- package/src/{test → testing}/metric-utils.ts +1 -1
- package/src/{test → testing}/test-processor-server.ts +2 -2
- package/src/{test → testing}/test-provider.ts +4 -2
- package/src/{test → tests}/abis/evm/CommitmentPool.json +0 -0
- package/src/{test → tests}/abis/evm/Seaport.json +0 -0
- package/src/{test → tests}/abis/evm/anyswapRouter.json +0 -0
- package/src/{test → tests}/abis/solana/basic_1.json +0 -0
- package/src/{test → tests}/aptos.test.ts +6 -2
- package/src/{test → tests}/codegen.test.ts +0 -0
- package/src/{test → tests}/erc20-template.test.ts +1 -1
- package/src/{test → tests}/erc20.test.ts +2 -3
- package/src/{test → tests}/erc20.ts +0 -0
- package/src/{test → tests}/error-capture.test.ts +4 -4
- package/src/{test → tests}/solana.test.ts +3 -4
- package/src/{test → tests}/souffl3.ts +1 -2
- package/src/{test → tests}/sui.test.ts +6 -3
- package/src/{test → tests}/types/basic_1.ts +0 -0
- package/src/{test → tests}/types/basic_1_processor.ts +0 -0
- package/src/{test → tests}/wormhole-token-bridge.ts +1 -2
- package/src/utils/{chainmap.ts → chain.ts} +13 -3
- package/src/utils/{convert.ts → conversion.ts} +1 -1
- package/src/utils/dex-price.test.ts +2 -1
- package/src/utils/dex-price.ts +6 -6
- package/src/utils/erc20.test.ts +6 -3
- package/src/utils/index.ts +4 -5
- package/src/utils/{erc20.ts → token.ts} +2 -2
- package/template/src/processor.test.ts +1 -2
- package/template/src/processor.ts +5 -5
- package/lib/aptos-processor.js.map +0 -1
- package/lib/base-processor-template.js.map +0 -1
- package/lib/base-processor.js.map +0 -1
- package/lib/bind-options.js.map +0 -1
- package/lib/context.js.map +0 -1
- package/lib/generic-processor.js.map +0 -1
- package/lib/meter.js.map +0 -1
- package/lib/meter.test.js.map +0 -1
- package/lib/numberish.js.map +0 -1
- package/lib/numberish.test.js.map +0 -1
- package/lib/solana/builtin/spl-token-processor.js.map +0 -1
- package/lib/solana/builtin/wormhole-processor.js.map +0 -1
- package/lib/solana-processor.js.map +0 -1
- package/lib/sui-processor.js.map +0 -1
- package/lib/test/aptos.test.js.map +0 -1
- package/lib/test/codegen.test.js.map +0 -1
- package/lib/test/erc20-template.test.js.map +0 -1
- package/lib/test/erc20.js.map +0 -1
- package/lib/test/erc20.test.js.map +0 -1
- package/lib/test/error-capture.test.js.map +0 -1
- package/lib/test/generic-processor.test.js.map +0 -1
- package/lib/test/index.js.map +0 -1
- package/lib/test/metric-utils.js.map +0 -1
- package/lib/test/solana.test.js.map +0 -1
- package/lib/test/souffl3.js.map +0 -1
- package/lib/test/sui.test.js.map +0 -1
- package/lib/test/test-processor-server.js.map +0 -1
- package/lib/test/test-provider.js.map +0 -1
- package/lib/test/types/basic_1.js.map +0 -1
- package/lib/test/types/basic_1_processor.js.map +0 -1
- package/lib/test/wormhole-token-bridge.js.map +0 -1
- package/lib/trace.js.map +0 -1
- package/lib/utils/chainmap.d.ts +0 -2
- package/lib/utils/chainmap.js.map +0 -1
- package/lib/utils/convert.js.map +0 -1
- package/lib/utils/erc20.js.map +0 -1
package/src/service.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
2
2
|
import { CallContext, ServerError, Status } from 'nice-grpc'
|
|
3
|
+
import { APTOS_TESTNET_ID, SOL_MAINMET_ID, SUI_DEVNET_ID } from './utils/chain'
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
BlockBinding,
|
|
@@ -29,10 +30,12 @@ import {
|
|
|
29
30
|
import { Empty } from './gen/google/protobuf/empty'
|
|
30
31
|
import Long from 'long'
|
|
31
32
|
import { TextDecoder } from 'util'
|
|
32
|
-
import { Trace } from './
|
|
33
|
+
import { Trace } from './core'
|
|
33
34
|
|
|
34
35
|
const DEFAULT_MAX_BLOCK = Long.ZERO
|
|
35
36
|
|
|
37
|
+
const USER_PROCESSOR = 'user_processor'
|
|
38
|
+
|
|
36
39
|
export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
37
40
|
private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []
|
|
38
41
|
private traceHandlers: ((trace: Trace) => Promise<ProcessResult>)[] = []
|
|
@@ -82,7 +85,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
82
85
|
// this.processorsByChainId.set(chainId, processor)
|
|
83
86
|
|
|
84
87
|
const contractConfig: ContractConfig = {
|
|
85
|
-
processorType:
|
|
88
|
+
processorType: USER_PROCESSOR,
|
|
86
89
|
contract: {
|
|
87
90
|
name: processor.config.name,
|
|
88
91
|
chainId: chainId.toString(),
|
|
@@ -155,10 +158,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
155
158
|
// Part 2, prepare solana constractors
|
|
156
159
|
for (const solanaProcessor of global.PROCESSOR_STATE.solanaProcessors) {
|
|
157
160
|
const contractConfig: ContractConfig = {
|
|
158
|
-
processorType:
|
|
161
|
+
processorType: USER_PROCESSOR,
|
|
159
162
|
contract: {
|
|
160
163
|
name: solanaProcessor.contractName,
|
|
161
|
-
chainId:
|
|
164
|
+
chainId: SOL_MAINMET_ID, // TODO set in processor
|
|
162
165
|
address: solanaProcessor.address,
|
|
163
166
|
abi: '',
|
|
164
167
|
},
|
|
@@ -179,10 +182,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
179
182
|
// Part 3, prepare sui constractors
|
|
180
183
|
for (const suiProcessor of global.PROCESSOR_STATE.suiProcessors) {
|
|
181
184
|
const contractConfig: ContractConfig = {
|
|
182
|
-
processorType:
|
|
185
|
+
processorType: USER_PROCESSOR,
|
|
183
186
|
contract: {
|
|
184
|
-
name: 'sui
|
|
185
|
-
chainId:
|
|
187
|
+
name: 'sui contract',
|
|
188
|
+
chainId: SUI_DEVNET_ID,
|
|
186
189
|
address: suiProcessor.address,
|
|
187
190
|
abi: '',
|
|
188
191
|
},
|
|
@@ -199,10 +202,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
199
202
|
// Part 3, prepare aptos constractors
|
|
200
203
|
for (const aptosProcessor of global.PROCESSOR_STATE.aptosProcessors) {
|
|
201
204
|
const contractConfig: ContractConfig = {
|
|
202
|
-
processorType:
|
|
205
|
+
processorType: USER_PROCESSOR,
|
|
203
206
|
contract: {
|
|
204
|
-
name:
|
|
205
|
-
chainId:
|
|
207
|
+
name: aptosProcessor.name,
|
|
208
|
+
chainId: APTOS_TESTNET_ID,
|
|
206
209
|
address: aptosProcessor.address,
|
|
207
210
|
abi: '',
|
|
208
211
|
},
|
|
@@ -336,20 +339,13 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
336
339
|
processorPromises.push(
|
|
337
340
|
new Promise((resolve, _) => {
|
|
338
341
|
for (const processor of global.PROCESSOR_STATE.suiProcessors) {
|
|
339
|
-
const res = processor.handleTransaction(
|
|
342
|
+
const res = processor.handleTransaction(
|
|
343
|
+
JSON.parse(new TextDecoder().decode(txn.raw)),
|
|
344
|
+
txn.slot ?? Long.fromNumber(0)
|
|
345
|
+
)
|
|
340
346
|
if (res) {
|
|
341
|
-
res.gauges.forEach((g) =>
|
|
342
|
-
|
|
343
|
-
g.metadata.blockNumber = txn.slot
|
|
344
|
-
}
|
|
345
|
-
result.gauges.push(g)
|
|
346
|
-
})
|
|
347
|
-
res.counters.forEach((c) => {
|
|
348
|
-
if (c.metadata && txn.slot) {
|
|
349
|
-
c.metadata.blockNumber = txn.slot
|
|
350
|
-
}
|
|
351
|
-
result.counters.push(c)
|
|
352
|
-
})
|
|
347
|
+
res.gauges.forEach((g) => result.gauges.push(g))
|
|
348
|
+
res.counters.forEach((c) => result.counters.push(c))
|
|
353
349
|
}
|
|
354
350
|
}
|
|
355
351
|
resolve()
|
|
@@ -366,20 +362,13 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
366
362
|
new Promise((resolve, _) => {
|
|
367
363
|
for (const processor of global.PROCESSOR_STATE.aptosProcessors) {
|
|
368
364
|
if (processor.address === txn.programAccountId!) {
|
|
369
|
-
const res = processor.handleTransaction(
|
|
365
|
+
const res = processor.handleTransaction(
|
|
366
|
+
JSON.parse(new TextDecoder().decode(txn.raw)),
|
|
367
|
+
txn.slot ?? Long.fromNumber(0)
|
|
368
|
+
)
|
|
370
369
|
if (res) {
|
|
371
|
-
res.gauges.forEach((g) =>
|
|
372
|
-
|
|
373
|
-
g.metadata.blockNumber = txn.slot
|
|
374
|
-
}
|
|
375
|
-
result.gauges.push(g)
|
|
376
|
-
})
|
|
377
|
-
res.counters.forEach((c) => {
|
|
378
|
-
if (c.metadata && txn.slot) {
|
|
379
|
-
c.metadata.blockNumber = txn.slot
|
|
380
|
-
}
|
|
381
|
-
result.counters.push(c)
|
|
382
|
-
})
|
|
370
|
+
res.gauges.forEach((g) => result.gauges.push(g))
|
|
371
|
+
res.counters.forEach((c) => result.counters.push(c))
|
|
383
372
|
}
|
|
384
373
|
}
|
|
385
374
|
}
|
|
@@ -424,29 +413,18 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
424
413
|
if (processor.address === instruction.programAccountId) {
|
|
425
414
|
let res: ProcessResult | null
|
|
426
415
|
if (instruction.parsed) {
|
|
427
|
-
res = processor.handleInstruction(
|
|
416
|
+
res = processor.handleInstruction(
|
|
417
|
+
JSON.parse(new TextDecoder().decode(instruction.parsed)),
|
|
418
|
+
instruction.slot
|
|
419
|
+
)
|
|
428
420
|
} else if (instruction.instructionData) {
|
|
429
|
-
res = processor.handleInstruction(instruction.instructionData)
|
|
421
|
+
res = processor.handleInstruction(instruction.instructionData, instruction.slot)
|
|
430
422
|
} else {
|
|
431
423
|
continue
|
|
432
424
|
}
|
|
433
425
|
if (res) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (g.metadata) {
|
|
437
|
-
g.metadata.blockNumber = instruction.slot
|
|
438
|
-
}
|
|
439
|
-
result.gauges.push(g)
|
|
440
|
-
})
|
|
441
|
-
res.counters.forEach((c) => {
|
|
442
|
-
if (c.metadata) {
|
|
443
|
-
c.metadata.blockNumber = instruction.slot
|
|
444
|
-
}
|
|
445
|
-
result.counters.push(c)
|
|
446
|
-
})
|
|
447
|
-
} catch (e) {
|
|
448
|
-
console.error('error processing instruction ' + errorString(e))
|
|
449
|
-
}
|
|
426
|
+
res.gauges.forEach((g) => result.gauges.push(g))
|
|
427
|
+
res.counters.forEach((c) => result.counters.push(c))
|
|
450
428
|
} else {
|
|
451
429
|
console.warn(
|
|
452
430
|
`Failed to decode the instruction: ${instruction.instructionData} with slot: ${instruction.slot}`
|
|
@@ -327,12 +327,14 @@ function generateMockEventLogFunction(event: EventDeclaration, contractName: str
|
|
|
327
327
|
eventNameWithSignature = getFullSignatureForEvent(event)
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
+
const eventArgs = event.inputs.map((input, i) => `event.${input.name ?? `arg${i.toString()}`}`)
|
|
331
|
+
|
|
330
332
|
return `
|
|
331
333
|
export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): Log {
|
|
332
334
|
const contract = get${contractName}Contract(contractAddress)
|
|
333
335
|
const encodedLog = contract.rawContract.interface.encodeEventLog(
|
|
334
336
|
contract.rawContract.interface.getEvent('${eventNameWithSignature}'),
|
|
335
|
-
|
|
337
|
+
[${eventArgs.join(', ')}]
|
|
336
338
|
)
|
|
337
339
|
return {
|
|
338
340
|
...mockField,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { TestProcessorServer } from './test-processor-server'
|
|
2
|
-
export { loadTestProvidersFromEnv } from './test-provider'
|
|
3
2
|
export { MetricValueToNumber, firstCounterValue, firstGaugeValue } from './metric-utils'
|
|
3
|
+
|
|
4
|
+
// export { loadTestProvidersFromEnv } from './test-provider' // TODO make the interface more standard and then export
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepPartial } from '../gen/builtin'
|
|
2
2
|
import { BigDecimal, MetricValue, ProcessResult } from '@sentio/sdk'
|
|
3
|
-
import { Numberish } from '../
|
|
3
|
+
import { Numberish } from '../core'
|
|
4
4
|
import { BigNumber } from 'ethers'
|
|
5
5
|
|
|
6
6
|
export function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Numberish | undefined {
|
|
@@ -24,11 +24,11 @@ import {
|
|
|
24
24
|
import { CallContext } from 'nice-grpc-common'
|
|
25
25
|
import { Empty } from '../gen/google/protobuf/empty'
|
|
26
26
|
import { ChainConfig } from '../chain-config'
|
|
27
|
-
import { CHAIN_MAP } from '../utils/
|
|
27
|
+
import { CHAIN_MAP } from '../utils/chain'
|
|
28
28
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
29
29
|
import Long from 'long'
|
|
30
30
|
import { getNetwork, Networkish } from '@ethersproject/providers'
|
|
31
|
-
import { Trace } from '
|
|
31
|
+
import { Trace } from '@sentio/sdk'
|
|
32
32
|
|
|
33
33
|
const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
34
34
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ChainConfig } from '../chain-config'
|
|
2
|
+
import { CHAIN_MAP } from '../utils/chain'
|
|
2
3
|
import { setProvider } from '@sentio/sdk'
|
|
3
|
-
import { CHAIN_MAP } from '../utils/chainmap'
|
|
4
4
|
|
|
5
5
|
export function loadTestProvidersFromEnv(requiredChainIds: string[] | string): boolean {
|
|
6
6
|
const dummyConfig: Record<string, ChainConfig> = {}
|
|
7
|
+
const found: string[] = []
|
|
7
8
|
|
|
8
9
|
if (!Array.isArray(requiredChainIds)) {
|
|
9
10
|
requiredChainIds = [requiredChainIds]
|
|
@@ -15,6 +16,7 @@ export function loadTestProvidersFromEnv(requiredChainIds: string[] | string): b
|
|
|
15
16
|
if (!http) {
|
|
16
17
|
continue
|
|
17
18
|
}
|
|
19
|
+
found.push(k)
|
|
18
20
|
dummyConfig[k] = {
|
|
19
21
|
ChainID: k,
|
|
20
22
|
Https: [http],
|
|
@@ -23,7 +25,7 @@ export function loadTestProvidersFromEnv(requiredChainIds: string[] | string): b
|
|
|
23
25
|
|
|
24
26
|
setProvider(dummyConfig)
|
|
25
27
|
for (const id of requiredChainIds) {
|
|
26
|
-
if (!
|
|
28
|
+
if (!found.includes(id)) {
|
|
27
29
|
return false
|
|
28
30
|
}
|
|
29
31
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { expect } from 'chai'
|
|
2
|
+
import Long from 'long'
|
|
2
3
|
import { TextEncoder } from 'util'
|
|
3
4
|
import { ProcessTransactionsRequest } from '..'
|
|
5
|
+
import { chain } from '../utils'
|
|
4
6
|
|
|
5
|
-
import { TestProcessorServer } from '
|
|
7
|
+
import { TestProcessorServer } from '../testing'
|
|
6
8
|
|
|
7
9
|
describe('Test Aptos Example', () => {
|
|
8
10
|
const service = new TestProcessorServer(() => {
|
|
@@ -20,17 +22,19 @@ describe('Test Aptos Example', () => {
|
|
|
20
22
|
|
|
21
23
|
test('Check souffl3 transaction dispatch', async () => {
|
|
22
24
|
const request: ProcessTransactionsRequest = {
|
|
23
|
-
chainId:
|
|
25
|
+
chainId: chain.APTOS_TESTNET_ID,
|
|
24
26
|
transactions: [
|
|
25
27
|
{
|
|
26
28
|
raw: new TextEncoder().encode(JSON.stringify(testData)),
|
|
27
29
|
programAccountId: '4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
|
|
30
|
+
slot: Long.fromNumber(12345),
|
|
28
31
|
},
|
|
29
32
|
],
|
|
30
33
|
}
|
|
31
34
|
const res = await service.processTransactions(request)
|
|
32
35
|
expect(res.result?.counters).length(1)
|
|
33
36
|
expect(res.result?.gauges).length(0)
|
|
37
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(12345)
|
|
34
38
|
})
|
|
35
39
|
})
|
|
36
40
|
|
|
File without changes
|
|
@@ -2,7 +2,7 @@ import { expect } from 'chai'
|
|
|
2
2
|
|
|
3
3
|
import { StartRequest } from '..'
|
|
4
4
|
import Long from 'long'
|
|
5
|
-
import { TestProcessorServer } from '
|
|
5
|
+
import { TestProcessorServer } from '../testing'
|
|
6
6
|
import { ERC20Processor, ERC20ProcessorTemplate } from '../builtin/internal/erc20_processor'
|
|
7
7
|
|
|
8
8
|
describe('Test Template', () => {
|
|
@@ -4,11 +4,10 @@ import { expect } from 'chai'
|
|
|
4
4
|
|
|
5
5
|
import { HandlerType } from '..'
|
|
6
6
|
|
|
7
|
-
import { TestProcessorServer } from '
|
|
8
|
-
import { firstCounterValue, firstGaugeValue } from './metric-utils'
|
|
7
|
+
import { TestProcessorServer, firstCounterValue, firstGaugeValue } from '../testing'
|
|
9
8
|
import { BigNumber } from 'ethers'
|
|
10
9
|
import { mockTransferLog } from '../builtin/erc20/test-utils'
|
|
11
|
-
import { Trace } from '
|
|
10
|
+
import { Trace } from '@sentio/sdk'
|
|
12
11
|
|
|
13
12
|
describe('Test Basic Examples', () => {
|
|
14
13
|
const service = new TestProcessorServer(() => require('./erc20'))
|
|
File without changes
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { assert } from 'chai'
|
|
2
2
|
|
|
3
|
-
import { TestProcessorServer } from '
|
|
3
|
+
import { TestProcessorServer } from '../testing'
|
|
4
4
|
import { BigNumber } from 'ethers'
|
|
5
5
|
import { mockApprovalLog, mockOwnershipTransferredLog, mockTransferLog } from '../builtin/erc20/test-utils'
|
|
6
6
|
import { ERC20Processor } from '../builtin/internal/erc20_processor'
|
|
7
|
-
import {
|
|
7
|
+
import { conversion } from '../utils'
|
|
8
8
|
import { BigDecimal } from '@sentio/sdk'
|
|
9
9
|
|
|
10
10
|
describe('Test Error Capture', () => {
|
|
11
11
|
const service = new TestProcessorServer(() => {
|
|
12
12
|
ERC20Processor.bind({ address: '0x80009ff8154bd5653c6dda2fa5f5053e5a5c1a91' })
|
|
13
13
|
.onEventApproval((evt, ctx) => {
|
|
14
|
-
const v = new BigDecimal(1).div(toBigDecimal(evt.args.value))
|
|
14
|
+
const v = new BigDecimal(1).div(conversion.toBigDecimal(evt.args.value))
|
|
15
15
|
ctx.meter.Gauge('xx').record(v)
|
|
16
16
|
})
|
|
17
17
|
.onEventTransfer((evt, ctx) => {
|
|
18
|
-
const v = new BigDecimal(0).div(toBigDecimal(evt.args.value))
|
|
18
|
+
const v = new BigDecimal(0).div(conversion.toBigDecimal(evt.args.value))
|
|
19
19
|
ctx.meter.Gauge('xx').record(v)
|
|
20
20
|
})
|
|
21
21
|
.onEventOwnershipTransferred((evt, ctx) => {
|
|
@@ -6,8 +6,7 @@ import { HandlerType, ProcessInstructionsRequest } from '..'
|
|
|
6
6
|
|
|
7
7
|
import Long from 'long'
|
|
8
8
|
import { TextEncoder } from 'util'
|
|
9
|
-
import { TestProcessorServer } from '
|
|
10
|
-
import { firstCounterValue } from './metric-utils'
|
|
9
|
+
import { TestProcessorServer, firstCounterValue } from '../testing'
|
|
11
10
|
|
|
12
11
|
describe('Test Solana Example', () => {
|
|
13
12
|
const service = new TestProcessorServer(() => {
|
|
@@ -28,7 +27,7 @@ describe('Test Solana Example', () => {
|
|
|
28
27
|
instructions: [
|
|
29
28
|
{
|
|
30
29
|
instructionData: '33G5T8yXAQWdH8FX7fTy1mBJ6e4dUKfQWbViSrT7qJjpS8UAA3ftEQx9sNzrkaJm56xtENhDsWf',
|
|
31
|
-
slot: Long.fromNumber(
|
|
30
|
+
slot: Long.fromNumber(12345),
|
|
32
31
|
programAccountId: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
|
|
33
32
|
},
|
|
34
33
|
{
|
|
@@ -41,7 +40,7 @@ describe('Test Solana Example', () => {
|
|
|
41
40
|
const res = await service.processInstructions(request)
|
|
42
41
|
expect(res.result?.counters).length(2)
|
|
43
42
|
expect(res.result?.gauges).length(0)
|
|
44
|
-
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(
|
|
43
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(12345)
|
|
45
44
|
expect(firstCounterValue(res.result, 'total_transfer_amount')).equal(1000000n)
|
|
46
45
|
expect(res.result?.counters[0].runtimeInfo?.from).equals(HandlerType.INSTRUCTION)
|
|
47
46
|
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AptosBindOptions } from '
|
|
2
|
-
import { AptosBaseProcessor } from '../aptos-processor'
|
|
1
|
+
import { AptosBindOptions, AptosBaseProcessor } from '@sentio/sdk'
|
|
3
2
|
|
|
4
3
|
class Souffl3 extends AptosBaseProcessor {
|
|
5
4
|
static bind(options: AptosBindOptions): Souffl3 {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { expect } from 'chai'
|
|
2
|
+
import Long from 'long'
|
|
2
3
|
import { TextEncoder } from 'util'
|
|
3
4
|
import { ProcessTransactionsRequest, SuiBaseProcessor, SuiBindOptions } from '..'
|
|
5
|
+
import { chain } from '../utils'
|
|
4
6
|
|
|
5
|
-
import { TestProcessorServer } from '
|
|
7
|
+
import { TestProcessorServer } from '../testing'
|
|
6
8
|
|
|
7
9
|
describe('Test Sui Example', () => {
|
|
8
10
|
const service = new TestProcessorServer(() => {
|
|
@@ -49,10 +51,10 @@ describe('Test Sui Example', () => {
|
|
|
49
51
|
|
|
50
52
|
test('Check tictactoe transaction dispatch', async () => {
|
|
51
53
|
const request: ProcessTransactionsRequest = {
|
|
52
|
-
chainId:
|
|
54
|
+
chainId: chain.SUI_DEVNET_ID,
|
|
53
55
|
transactions: [
|
|
54
56
|
{
|
|
55
|
-
|
|
57
|
+
slot: Long.fromNumber(12345),
|
|
56
58
|
raw: new TextEncoder().encode(JSON.stringify(testData)),
|
|
57
59
|
programAccountId: '0xb8252513f0b9efaa3e260842c4b84d8ff933522d',
|
|
58
60
|
},
|
|
@@ -61,6 +63,7 @@ describe('Test Sui Example', () => {
|
|
|
61
63
|
const res = await service.processTransactions(request)
|
|
62
64
|
expect(res.result?.counters).length(1)
|
|
63
65
|
expect(res.result?.gauges).length(0)
|
|
66
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(12345)
|
|
64
67
|
})
|
|
65
68
|
})
|
|
66
69
|
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { TokenBridgeProcessor } from '../
|
|
2
|
-
import { SPLTokenProcessor } from '../solana/builtin'
|
|
1
|
+
import { TokenBridgeProcessor, SPLTokenProcessor } from '../builtin/solana'
|
|
3
2
|
|
|
4
3
|
TokenBridgeProcessor.bind({
|
|
5
4
|
address: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
// and https://besu.hyperledger.org/en/stable/Concepts/NetworkID-And-ChainID/
|
|
3
3
|
|
|
4
4
|
export const CHAIN_MAP: Record<string, string> = {
|
|
5
|
-
SOL_mainnet: 'solana',
|
|
6
|
-
SOL_devnet: 'solana-dev',
|
|
7
|
-
SOL_testnet: 'solana-test',
|
|
8
5
|
0: 'kardia',
|
|
9
6
|
1: 'ethereum',
|
|
10
7
|
2: 'expanse',
|
|
@@ -83,6 +80,19 @@ export const CHAIN_MAP: Record<string, string> = {
|
|
|
83
80
|
836542336838601: 'curio',
|
|
84
81
|
}
|
|
85
82
|
|
|
83
|
+
export const SOL_MAINMET_ID = 'sol_mainnet'
|
|
84
|
+
export const SOL_DEVNET_ID = 'sol_devnet'
|
|
85
|
+
export const SOL_TESTNENT_ID = 'sol_testnet'
|
|
86
|
+
CHAIN_MAP[SOL_MAINMET_ID] = 'solana'
|
|
87
|
+
CHAIN_MAP[SOL_DEVNET_ID] = 'solana-dev'
|
|
88
|
+
CHAIN_MAP[SOL_TESTNENT_ID] = 'solana-test'
|
|
89
|
+
|
|
90
|
+
export const SUI_DEVNET_ID = 'sui_devnet'
|
|
91
|
+
CHAIN_MAP[SUI_DEVNET_ID] = 'sui-dev'
|
|
92
|
+
|
|
93
|
+
export const APTOS_TESTNET_ID = 'aptos_testnet'
|
|
94
|
+
CHAIN_MAP[APTOS_TESTNET_ID] = 'aptos-test'
|
|
95
|
+
|
|
86
96
|
export function getChainName(chainId: string | number): string {
|
|
87
97
|
if (typeof chainId === 'number') {
|
|
88
98
|
chainId = chainId.toString()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EthereumDexPrice, GoerliDexPrice } from './dex-price'
|
|
2
2
|
import { ProcessorState } from '@sentio/sdk'
|
|
3
|
-
import { loadTestProvidersFromEnv } from '../test'
|
|
3
|
+
import { loadTestProvidersFromEnv } from '../testing/test-provider'
|
|
4
|
+
|
|
4
5
|
import { expect } from 'chai'
|
|
5
6
|
|
|
6
7
|
describe('dex price tests', () => {
|
package/src/utils/dex-price.ts
CHANGED
|
@@ -4,7 +4,7 @@ import fs from 'fs'
|
|
|
4
4
|
|
|
5
5
|
import { parse } from 'csv-parse/sync'
|
|
6
6
|
import { BlockTag } from '@ethersproject/providers'
|
|
7
|
-
import { scaleDown } from './
|
|
7
|
+
import { scaleDown } from './token'
|
|
8
8
|
|
|
9
9
|
type OralceRecord = {
|
|
10
10
|
Pair: string
|
|
@@ -27,12 +27,12 @@ export interface DexPriceResult {
|
|
|
27
27
|
// Load price feed from https://docs.chain.link/docs/data-feeds/price-feeds/addresses/?network=ethereum
|
|
28
28
|
// and then use EACAggregatorProxy contract to get price
|
|
29
29
|
class DexPrice {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
USD_ORACLE_MAP = new Map<string, string>()
|
|
31
|
+
ETH_ORACLE_MAP = new Map<string, string>()
|
|
32
|
+
BTC_ORACLE_MAP = new Map<string, string>()
|
|
33
|
+
ASSETS_INFOS = new Map<string, number>()
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
readonly chainId: number
|
|
36
36
|
|
|
37
37
|
constructor(csvFileName: string, chainId: number) {
|
|
38
38
|
this.chainId = chainId
|
package/src/utils/erc20.test.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { ProcessorState } from '@sentio/sdk'
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ProcessorState, DummyProvider } from '@sentio/sdk'
|
|
2
|
+
|
|
3
|
+
console.log(DummyProvider)
|
|
4
|
+
|
|
5
|
+
import { getERC20TokenInfo } from './token'
|
|
6
|
+
import { loadTestProvidersFromEnv } from '../testing/test-provider'
|
|
4
7
|
|
|
5
8
|
describe('erc20 tests', () => {
|
|
6
9
|
global.PROCESSOR_STATE = new ProcessorState()
|
package/src/utils/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export type { DexPriceResult } from './dex-price'
|
|
1
|
+
export * as chain from './chain'
|
|
2
|
+
export * as conversion from './conversion'
|
|
3
|
+
export * as token from './token'
|
|
4
|
+
export * as dexPrice from './dex-price'
|
|
@@ -4,10 +4,10 @@ import { transformEtherError } from '../error'
|
|
|
4
4
|
import { getERC20Contract } from '../builtin/erc20'
|
|
5
5
|
import { getERC20BytesContract } from '../builtin/internal/erc20bytes_processor'
|
|
6
6
|
import { BigDecimal } from '@sentio/sdk'
|
|
7
|
-
import { toBigDecimal } from './
|
|
7
|
+
import { toBigDecimal } from './conversion'
|
|
8
8
|
import { utils } from 'ethers'
|
|
9
9
|
|
|
10
|
-
export
|
|
10
|
+
export interface TokenInfo {
|
|
11
11
|
symbol: string
|
|
12
12
|
name: string
|
|
13
13
|
decimal: number
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { TestProcessorServer } from '@sentio/sdk/lib/
|
|
1
|
+
import { TestProcessorServer, firstCounterValue } from '@sentio/sdk/lib/testing'
|
|
2
2
|
import { mockTransferLog } from '@sentio/sdk/lib/builtin/erc20/test-utils'
|
|
3
|
-
import { firstCounterValue } from '@sentio/sdk/lib/test/metric-utils'
|
|
4
3
|
import { BigNumber } from 'ethers'
|
|
5
4
|
|
|
6
5
|
describe('Test Processor', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Counter, Gauge } from '@sentio/sdk'
|
|
2
|
-
import {
|
|
2
|
+
import { token } from '@sentio/sdk/lib/utils'
|
|
3
3
|
import { ERC20Processor } from '@sentio/sdk/lib/builtin/erc20'
|
|
4
4
|
import { X2y2Processor } from './types/x2y2'
|
|
5
5
|
|
|
@@ -7,11 +7,11 @@ const rewardPerBlock = new Gauge('reward_per_block', {
|
|
|
7
7
|
description: 'rewards for each block grouped by phase',
|
|
8
8
|
unit: 'x2y2',
|
|
9
9
|
})
|
|
10
|
-
const
|
|
10
|
+
const tokenCounter = new Counter('token')
|
|
11
11
|
|
|
12
12
|
X2y2Processor.bind({ address: '0xB329e39Ebefd16f40d38f07643652cE17Ca5Bac1' }).onBlock(async (_, ctx) => {
|
|
13
13
|
const phase = (await ctx.contract.currentPhase()).toString()
|
|
14
|
-
const reward =
|
|
14
|
+
const reward = token.scaleDown(await ctx.contract.rewardPerBlockForStaking(), 18)
|
|
15
15
|
rewardPerBlock.record(ctx, reward, { phase })
|
|
16
16
|
})
|
|
17
17
|
|
|
@@ -22,8 +22,8 @@ const filter = ERC20Processor.filters.Transfer(
|
|
|
22
22
|
|
|
23
23
|
ERC20Processor.bind({ address: '0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9' }).onEventTransfer(
|
|
24
24
|
async (event, ctx) => {
|
|
25
|
-
const val =
|
|
26
|
-
|
|
25
|
+
const val = token.scaleDown(event.args.value, 18)
|
|
26
|
+
tokenCounter.add(ctx, val)
|
|
27
27
|
},
|
|
28
28
|
filter // filter is an optional parameter
|
|
29
29
|
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../src/aptos-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAwC;AAExC,gDAAuB;AAOvB,MAAa,kBAAkB;IACtB,kBAAkB,CAA+C;IACxE,OAAO,CAAQ;IACf,MAAM,GAAmB,EAAE,cAAc,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IAExD,YAAY,OAAyB;QACnC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,MAAM,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,IAAI,CAAC,OAAyB;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,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Y,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAhED,gDAgEC","sourcesContent":["import { AptosBindOptions } from './bind-options'\nimport { AptosContext } from './context'\nimport { ProcessResult } from './index'\nimport Long from 'long'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport class AptosBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: AptosContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n\n constructor(options: AptosBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.aptosProcessors.push(this)\n }\n\n bind(options: AptosBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n }\n\n public onTransaction(handler: (transaction: any, ctx: AptosContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.transactionHanlder = handler\n\n return this\n }\n\n public handleTransaction(txn: any): ProcessResult | null {\n const ctx = new AptosContext(this.address)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: [],\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../src/base-processor-template.ts"],"names":[],"mappings":";;;;;;AAKA,iDAAiE;AAEjE,gDAAuB;AACvB,wDAAqD;AAIrD,MAAsB,qBAAqB;IAIzC,EAAE,CAAQ;IACV,KAAK,GAAG,IAA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E,cAAI,CAAC,IAAI;SACpB,CAAA;QACD,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,EAAE;gBAC1C,QAAQ,CAAC,UAAU,GAAG,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;aAC1D;iBAAM;gBACL,QAAQ,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;aACzC;SACF;QACD,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACxC,QAAQ,CAAC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;aACtD;iBAAM;gBACL,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;aACrC;SACF;QACD,MAAM,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAExD,OAAO,SAAS,CAAA;IAClB,CAAC;IAEM,OAAO,CACZ,OAAqF,EACrF,MAAmC;QAEnC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,OAAO;YAChB,MAAM,EAAE,MAAM;SACf,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CAAC,OAAqF;QAClG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CACZ,SAAiB,EACjB,OAAqF;QAErF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC;CAGF;AA5FD,sDA4FC","sourcesContent":["import { BoundContractView, Context, ContractView } from './context'\nimport { Block } from '@ethersproject/abstract-provider'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Event } from '@ethersproject/contracts'\nimport { BaseProcessor } from './base-processor'\nimport { BindOptions, getOptionsSignature } from './bind-options'\nimport { TemplateInstance } from './gen/processor/protos/processor'\nimport Long from 'long'\nimport { getNetwork } from '@ethersproject/providers'\nimport { PromiseOrVoid } from './promise-or-void'\nimport { Trace } from './trace'\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: ((block: Block, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid)[] = []\n traceHandlers: {\n signature: string\n handler: (trace: Trace, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid\n }[] = []\n eventHandlers: {\n handler: (event: Event, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid\n filter: EventFilter | EventFilter[]\n }[] = []\n\n constructor() {\n this.id = global.PROCESSOR_STATE.templates.length\n global.PROCESSOR_STATE.templates.push(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)\n }\n for (const bh of this.blockHandlers) {\n processor.onBlock(bh)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: options.network ? getNetwork(options.network).chainId.toString() : '1',\n abi: '',\n },\n startBlock: Long.ZERO,\n endBlock: Long.ZERO,\n }\n if (options.startBlock) {\n if (typeof options.startBlock === 'number') {\n instance.startBlock = Long.fromNumber(options.startBlock)\n } else {\n instance.startBlock = options.startBlock\n }\n }\n if (options.endBlock) {\n if (typeof options.endBlock === 'number') {\n instance.endBlock = Long.fromNumber(options.endBlock)\n } else {\n instance.endBlock = options.endBlock\n }\n }\n global.PROCESSOR_STATE.templatesInstances.push(instance)\n\n return processor\n }\n\n public onEvent(\n handler: (event: Event, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid) {\n this.blockHandlers.push(handler)\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: Context<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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../src/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAAoE;AAMpE,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAoB,EAAE,CAAA;IACnC,aAAa,GAAmB,EAAE,CAAA;IAElC,IAAI,CAAQ;IACZ,MAAM,CAAqB;IAE3B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,UAAU,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC;SACxB,CAAA;QACD,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE;gBACzC,IAAI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AM,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;gBAE3E,MAAM,GAAG,GAAG,IAAI,iBAAO,CAAgC,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;gBAC1G,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBACzB,OAAO;oBACL,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;oBACtB,IAAI,EAAE,EAAE;iBACT,CAAA;YACH,CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AArJD,sCAqJC","sourcesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, Context, ContractView } from './context'\nimport { ProcessResult } from './gen/processor/protos/processor'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from './promise-or-void'\nimport { Trace } from './trace'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n name: string\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, undefined, log)\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: [],\n }\n }\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n\n this.blockHandlers.push(async function (block: Block) {\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, block, undefined)\n await handler(block, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: [],\n }\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: Context<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new Context<TContract, TBoundContractView>(contractView, chainId, undefined, undefined, trace)\n await handler(trace, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: [],\n }\n },\n })\n return this\n }\n}\n"]}
|