@sentio/sdk 1.19.4 → 1.19.6
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/aptos/aptos-processor.d.ts +41 -0
- package/lib/aptos/aptos-processor.js +129 -0
- package/lib/aptos/aptos-processor.js.map +1 -0
- package/lib/aptos/bind-options.d.ts +11 -0
- package/lib/aptos/bind-options.js +17 -0
- package/lib/aptos/bind-options.js.map +1 -0
- package/lib/aptos/context.d.ts +12 -0
- package/lib/aptos/context.js +33 -0
- package/lib/aptos/context.js.map +1 -0
- package/lib/aptos/index.d.ts +5 -0
- package/lib/aptos/index.js +11 -0
- package/lib/aptos/index.js.map +1 -0
- package/lib/cli/webpack.config.js +1 -0
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/base-processor.d.ts +1 -1
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/bind-options.d.ts +0 -2
- package/lib/core/bind-options.js +1 -4
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +10 -10
- package/lib/core/context.js +65 -11
- package/lib/core/context.js.map +1 -1
- package/lib/core/index.d.ts +1 -2
- package/lib/core/index.js +1 -4
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +1 -1
- package/lib/core/logger.js +5 -5
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +1 -1
- package/lib/core/metadata.js +3 -79
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +1 -1
- package/lib/core/meter.js +2 -2
- package/lib/core/meter.js.map +1 -1
- package/lib/core/numberish.d.ts +1 -1
- package/lib/core/numberish.js +7 -7
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/numberish.test.js.map +1 -1
- package/lib/core/solana-processor.d.ts +1 -1
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.d.ts +1 -1
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/gen/index.d.ts +1 -0
- package/lib/gen/index.js +18 -0
- package/lib/gen/index.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +15 -2
- package/lib/index.js.map +1 -1
- package/lib/processor-runner.js +2 -2
- package/lib/processor-runner.js.map +1 -1
- package/lib/processor-state.d.ts +2 -1
- package/lib/processor-state.js.map +1 -1
- package/lib/service.d.ts +2 -2
- package/lib/service.js +41 -36
- package/lib/service.js.map +1 -1
- package/lib/testing/metric-utils.d.ts +1 -1
- package/lib/testing/metric-utils.js +2 -2
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +2 -1
- package/lib/testing/test-processor-server.js +11 -11
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +2 -2
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/tests/aptos.test.js +44 -12
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/souffl3.js +19 -12
- package/lib/tests/souffl3.js.map +1 -1
- package/lib/utils/chain.d.ts +1 -0
- package/lib/utils/chain.js +3 -1
- package/lib/utils/chain.js.map +1 -1
- package/package.json +5 -7
- package/src/aptos/aptos-processor.ts +171 -0
- package/src/aptos/bind-options.ts +15 -0
- package/src/aptos/context.ts +35 -0
- package/src/aptos/index.ts +5 -0
- package/src/cli/webpack.config.js +1 -0
- package/src/core/base-processor-template.ts +1 -1
- package/src/core/base-processor.ts +1 -1
- package/src/core/bind-options.ts +0 -1
- package/src/core/context.ts +74 -15
- package/src/core/index.ts +2 -2
- package/src/core/logger.ts +1 -1
- package/src/core/metadata.ts +4 -76
- package/src/core/meter.ts +1 -1
- package/src/core/numberish.test.ts +1 -1
- package/src/core/numberish.ts +1 -1
- package/src/core/solana-processor.ts +1 -1
- package/src/core/sui-processor.ts +1 -1
- package/src/gen/index.ts +1 -0
- package/src/index.ts +4 -1
- package/src/processor-runner.ts +1 -1
- package/src/processor-state.ts +3 -1
- package/src/service.ts +29 -29
- package/src/testing/metric-utils.ts +2 -2
- package/src/testing/test-processor-server.ts +5 -2
- package/src/testing/test-provider.ts +1 -1
- package/src/tests/aptos.test.ts +47 -11
- package/src/tests/souffl3.ts +31 -19
- package/src/utils/chain.ts +2 -0
- package/lib/core/aptos-processor.d.ts +0 -41
- package/lib/core/aptos-processor.js +0 -125
- package/lib/core/aptos-processor.js.map +0 -1
- package/src/core/aptos-processor.ts +0 -147
|
@@ -4,7 +4,7 @@ import { BaseContract, EventFilter } from 'ethers'
|
|
|
4
4
|
import { Event } from '@ethersproject/contracts'
|
|
5
5
|
import { BaseProcessor } from './base-processor'
|
|
6
6
|
import { BindOptions, getOptionsSignature } from './bind-options'
|
|
7
|
-
import { TemplateInstance } from '../gen
|
|
7
|
+
import { TemplateInstance } from '../gen'
|
|
8
8
|
import Long from 'long'
|
|
9
9
|
import { getNetwork } from '@ethersproject/providers'
|
|
10
10
|
import { PromiseOrVoid } from '../promise-or-void'
|
|
@@ -5,7 +5,7 @@ import { BaseContract, EventFilter } from '@ethersproject/contracts'
|
|
|
5
5
|
import Long from 'long'
|
|
6
6
|
|
|
7
7
|
import { BoundContractView, Context, ContractView } from './context'
|
|
8
|
-
import { ProcessResult } from '../gen
|
|
8
|
+
import { ProcessResult } from '../gen'
|
|
9
9
|
import { BindInternalOptions, BindOptions } from './bind-options'
|
|
10
10
|
import { PromiseOrVoid } from '../promise-or-void'
|
|
11
11
|
import { Trace } from './trace'
|
package/src/core/bind-options.ts
CHANGED
package/src/core/context.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { CounterResult, GaugeResult, LogResult } from '../gen
|
|
1
|
+
import { CounterResult, GaugeResult, LogResult, MetricDescriptor, RecordMetaData } from '../gen'
|
|
2
2
|
import { BaseContract, EventFilter } from 'ethers'
|
|
3
3
|
import { Block, Log } from '@ethersproject/abstract-provider'
|
|
4
|
-
import { Meter } from './meter'
|
|
4
|
+
import { Meter, normalizeLabels } from './meter'
|
|
5
5
|
import Long from 'long'
|
|
6
6
|
import { Trace } from './trace'
|
|
7
7
|
import { Logger } from './logger'
|
|
8
|
+
import { Labels } from './metadata'
|
|
9
|
+
import { SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'
|
|
8
10
|
|
|
9
|
-
export class BaseContext {
|
|
11
|
+
export abstract class BaseContext {
|
|
10
12
|
gauges: GaugeResult[] = []
|
|
11
13
|
counters: CounterResult[] = []
|
|
12
14
|
logs: LogResult[] = []
|
|
13
15
|
meter: Meter
|
|
14
16
|
logger: Logger
|
|
15
17
|
|
|
16
|
-
constructor() {
|
|
18
|
+
protected constructor() {
|
|
17
19
|
this.meter = new Meter(this)
|
|
18
20
|
this.logger = new Logger(this)
|
|
19
21
|
}
|
|
22
|
+
|
|
23
|
+
abstract getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
export class EthContext extends BaseContext {
|
|
26
|
+
export abstract class EthContext extends BaseContext {
|
|
23
27
|
chainId: number
|
|
24
28
|
log?: Log
|
|
25
29
|
block?: Block
|
|
@@ -27,7 +31,7 @@ export class EthContext extends BaseContext {
|
|
|
27
31
|
blockNumber: Long
|
|
28
32
|
transactionHash?: string
|
|
29
33
|
|
|
30
|
-
constructor(chainId: number, block?: Block, log?: Log, trace?: Trace) {
|
|
34
|
+
protected constructor(chainId: number, block?: Block, log?: Log, trace?: Trace) {
|
|
31
35
|
super()
|
|
32
36
|
this.chainId = chainId
|
|
33
37
|
this.log = log
|
|
@@ -58,6 +62,46 @@ export class Context<
|
|
|
58
62
|
this.contract = view
|
|
59
63
|
this.address = view.rawContract.address
|
|
60
64
|
}
|
|
65
|
+
|
|
66
|
+
getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData {
|
|
67
|
+
if (this.log) {
|
|
68
|
+
return {
|
|
69
|
+
contractAddress: this.contract.rawContract.address,
|
|
70
|
+
blockNumber: this.blockNumber,
|
|
71
|
+
transactionIndex: this.log.transactionIndex,
|
|
72
|
+
transactionHash: this.transactionHash || '',
|
|
73
|
+
logIndex: this.log.logIndex,
|
|
74
|
+
chainId: this.chainId.toString(),
|
|
75
|
+
descriptor: descriptor,
|
|
76
|
+
labels: normalizeLabels(labels),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (this.block) {
|
|
80
|
+
return {
|
|
81
|
+
contractAddress: this.contract.rawContract.address,
|
|
82
|
+
blockNumber: this.blockNumber,
|
|
83
|
+
transactionIndex: -1,
|
|
84
|
+
transactionHash: '',
|
|
85
|
+
logIndex: -1,
|
|
86
|
+
chainId: this.chainId.toString(),
|
|
87
|
+
descriptor: descriptor,
|
|
88
|
+
labels: normalizeLabels(labels),
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (this.trace) {
|
|
92
|
+
return {
|
|
93
|
+
contractAddress: this.contract.rawContract.address,
|
|
94
|
+
blockNumber: this.blockNumber,
|
|
95
|
+
transactionIndex: this.trace.transactionPosition,
|
|
96
|
+
transactionHash: this.transactionHash || '',
|
|
97
|
+
logIndex: -1,
|
|
98
|
+
chainId: this.chainId.toString(),
|
|
99
|
+
descriptor: descriptor,
|
|
100
|
+
labels: normalizeLabels(labels),
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
throw new Error("Invaid ctx argument can't happen")
|
|
104
|
+
}
|
|
61
105
|
}
|
|
62
106
|
|
|
63
107
|
export class ContractView<TContract extends BaseContract> {
|
|
@@ -109,6 +153,19 @@ export class SolanaContext extends BaseContext {
|
|
|
109
153
|
this.address = address
|
|
110
154
|
this.blockNumber = slot
|
|
111
155
|
}
|
|
156
|
+
|
|
157
|
+
getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData {
|
|
158
|
+
return {
|
|
159
|
+
contractAddress: this.address,
|
|
160
|
+
blockNumber: this.blockNumber,
|
|
161
|
+
transactionIndex: 0,
|
|
162
|
+
transactionHash: '', // TODO add
|
|
163
|
+
logIndex: 0,
|
|
164
|
+
chainId: SOL_MAINMET_ID, // TODO set in context
|
|
165
|
+
descriptor: descriptor,
|
|
166
|
+
labels: normalizeLabels(labels),
|
|
167
|
+
}
|
|
168
|
+
}
|
|
112
169
|
}
|
|
113
170
|
|
|
114
171
|
export class SuiContext extends BaseContext {
|
|
@@ -120,15 +177,17 @@ export class SuiContext extends BaseContext {
|
|
|
120
177
|
this.address = address
|
|
121
178
|
this.blockNumber = slot
|
|
122
179
|
}
|
|
123
|
-
}
|
|
124
180
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
181
|
+
getMetaData(descriptor: MetricDescriptor | undefined, labels: Labels): RecordMetaData {
|
|
182
|
+
return {
|
|
183
|
+
contractAddress: this.address,
|
|
184
|
+
blockNumber: this.blockNumber,
|
|
185
|
+
transactionIndex: 0,
|
|
186
|
+
transactionHash: '', // TODO
|
|
187
|
+
logIndex: 0,
|
|
188
|
+
chainId: SUI_DEVNET_ID, // TODO set in context
|
|
189
|
+
descriptor: descriptor,
|
|
190
|
+
labels: normalizeLabels(labels),
|
|
191
|
+
}
|
|
133
192
|
}
|
|
134
193
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -3,13 +3,13 @@ export { Context, ContractView, BoundContractView, SolanaContext } from './conte
|
|
|
3
3
|
export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter'
|
|
4
4
|
export { type Numberish, toBigInteger, toMetricValue } from './numberish'
|
|
5
5
|
|
|
6
|
-
export { BindOptions, SolanaBindOptions, SuiBindOptions
|
|
6
|
+
export { BindOptions, SolanaBindOptions, SuiBindOptions } from './bind-options'
|
|
7
7
|
|
|
8
8
|
export { BaseProcessor } from './base-processor'
|
|
9
9
|
export { GenericProcessor } from './generic-processor'
|
|
10
10
|
export { BaseProcessorTemplate } from './base-processor-template'
|
|
11
11
|
export { SolanaBaseProcessor } from './solana-processor'
|
|
12
12
|
export { SuiBaseProcessor } from './sui-processor'
|
|
13
|
-
export
|
|
13
|
+
// export * from '../aptos'
|
|
14
14
|
|
|
15
15
|
export type { TypedCallTrace, Trace } from './trace'
|
package/src/core/logger.ts
CHANGED
package/src/core/metadata.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MetricDescriptor, RecordMetaData } from '
|
|
3
|
-
import {
|
|
4
|
-
import { Metric, normalizeLabels, normalizeName } from './meter'
|
|
1
|
+
import { BaseContext } from './context'
|
|
2
|
+
import { MetricDescriptor, RecordMetaData } from '../gen'
|
|
3
|
+
import { Metric, normalizeName } from './meter'
|
|
5
4
|
|
|
6
5
|
export type Labels = { [key: string]: string }
|
|
7
6
|
|
|
@@ -17,76 +16,5 @@ export function GetRecordMetaData(ctx: BaseContext, metric: Metric | undefined,
|
|
|
17
16
|
descriptor.name = normalizeName(descriptor.name)
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
if (ctx.log) {
|
|
22
|
-
return {
|
|
23
|
-
contractAddress: ctx.contract.rawContract.address,
|
|
24
|
-
blockNumber: ctx.blockNumber,
|
|
25
|
-
transactionIndex: ctx.log.transactionIndex,
|
|
26
|
-
transactionHash: ctx.transactionHash || '',
|
|
27
|
-
logIndex: ctx.log.logIndex,
|
|
28
|
-
chainId: ctx.chainId.toString(),
|
|
29
|
-
descriptor: descriptor,
|
|
30
|
-
labels: normalizeLabels(labels),
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (ctx.block) {
|
|
34
|
-
return {
|
|
35
|
-
contractAddress: ctx.contract.rawContract.address,
|
|
36
|
-
blockNumber: ctx.blockNumber,
|
|
37
|
-
transactionIndex: -1,
|
|
38
|
-
transactionHash: '',
|
|
39
|
-
logIndex: -1,
|
|
40
|
-
chainId: ctx.chainId.toString(),
|
|
41
|
-
descriptor: descriptor,
|
|
42
|
-
labels: normalizeLabels(labels),
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (ctx.trace) {
|
|
46
|
-
return {
|
|
47
|
-
contractAddress: ctx.contract.rawContract.address,
|
|
48
|
-
blockNumber: ctx.blockNumber,
|
|
49
|
-
transactionIndex: ctx.trace.transactionPosition,
|
|
50
|
-
transactionHash: ctx.transactionHash || '',
|
|
51
|
-
logIndex: -1,
|
|
52
|
-
chainId: ctx.chainId.toString(),
|
|
53
|
-
descriptor: descriptor,
|
|
54
|
-
labels: normalizeLabels(labels),
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
} else if (ctx instanceof SolanaContext) {
|
|
58
|
-
return {
|
|
59
|
-
contractAddress: ctx.address,
|
|
60
|
-
blockNumber: ctx.blockNumber,
|
|
61
|
-
transactionIndex: 0,
|
|
62
|
-
transactionHash: '', // TODO add
|
|
63
|
-
logIndex: 0,
|
|
64
|
-
chainId: SOL_MAINMET_ID, // TODO set in context
|
|
65
|
-
descriptor: descriptor,
|
|
66
|
-
labels: normalizeLabels(labels),
|
|
67
|
-
}
|
|
68
|
-
} else if (ctx instanceof SuiContext) {
|
|
69
|
-
return {
|
|
70
|
-
contractAddress: ctx.address,
|
|
71
|
-
blockNumber: ctx.blockNumber,
|
|
72
|
-
transactionIndex: 0,
|
|
73
|
-
transactionHash: '', // TODO
|
|
74
|
-
logIndex: 0,
|
|
75
|
-
chainId: SUI_DEVNET_ID, // TODO set in context
|
|
76
|
-
descriptor: descriptor,
|
|
77
|
-
labels: normalizeLabels(labels),
|
|
78
|
-
}
|
|
79
|
-
} else if (ctx instanceof AptosContext) {
|
|
80
|
-
return {
|
|
81
|
-
contractAddress: ctx.address,
|
|
82
|
-
blockNumber: ctx.blockNumber,
|
|
83
|
-
transactionIndex: 0,
|
|
84
|
-
transactionHash: '', // TODO
|
|
85
|
-
logIndex: 0,
|
|
86
|
-
chainId: APTOS_TESTNET_ID, // TODO set in context
|
|
87
|
-
descriptor: descriptor,
|
|
88
|
-
labels: normalizeLabels(labels),
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
throw new Error("This can't happen")
|
|
19
|
+
return ctx.getMetaData(descriptor, labels)
|
|
92
20
|
}
|
package/src/core/meter.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { toBigInteger, toMetricValue } from './numberish'
|
|
|
3
3
|
import { webcrypto } from 'crypto'
|
|
4
4
|
import { BigNumber } from 'ethers'
|
|
5
5
|
import { performance } from 'perf_hooks'
|
|
6
|
-
import { BigInteger } from '../gen
|
|
6
|
+
import { BigInteger } from '../gen'
|
|
7
7
|
import { BigDecimal } from '.'
|
|
8
8
|
|
|
9
9
|
// TODO add test for type conversion
|
package/src/core/numberish.ts
CHANGED
package/src/gen/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../gen/processor/protos/processor'
|
package/src/index.ts
CHANGED
|
@@ -7,5 +7,8 @@ export { EthersError } from './error'
|
|
|
7
7
|
|
|
8
8
|
export { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'
|
|
9
9
|
|
|
10
|
-
export * from './gen
|
|
10
|
+
export * from './gen'
|
|
11
|
+
|
|
11
12
|
export * from './core'
|
|
13
|
+
|
|
14
|
+
export * as aptos from './aptos'
|
package/src/processor-runner.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import commandLineArgs from 'command-line-args'
|
|
4
4
|
import { createServer } from 'nice-grpc'
|
|
5
|
-
import { ProcessorDefinition } from './gen
|
|
5
|
+
import { ProcessorDefinition } from './gen'
|
|
6
6
|
import { ProcessorServiceImpl } from './service'
|
|
7
7
|
import { setProvider } from './provider'
|
|
8
8
|
|
package/src/processor-state.ts
CHANGED
|
@@ -5,8 +5,10 @@ import {
|
|
|
5
5
|
BaseProcessorTemplate,
|
|
6
6
|
SolanaBaseProcessor,
|
|
7
7
|
SuiBaseProcessor,
|
|
8
|
-
AptosBaseProcessor,
|
|
9
8
|
} from './core'
|
|
9
|
+
|
|
10
|
+
import { AptosBaseProcessor } from './aptos'
|
|
11
|
+
|
|
10
12
|
import { BaseContract } from 'ethers'
|
|
11
13
|
import { TemplateInstance } from './gen/processor/protos/processor'
|
|
12
14
|
import { Provider } from '@ethersproject/providers'
|
package/src/service.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
ProcessTransactionsRequest,
|
|
23
23
|
StartRequest,
|
|
24
24
|
TemplateInstance,
|
|
25
|
-
} from './gen
|
|
25
|
+
} from './gen'
|
|
26
26
|
|
|
27
27
|
import { Empty } from './gen/google/protobuf/empty'
|
|
28
28
|
import Long from 'long'
|
|
@@ -213,13 +213,13 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
213
213
|
contract: {
|
|
214
214
|
name: aptosProcessor.name,
|
|
215
215
|
chainId: APTOS_TESTNET_ID,
|
|
216
|
-
address: aptosProcessor.address,
|
|
216
|
+
address: aptosProcessor.config.address,
|
|
217
217
|
abi: '',
|
|
218
218
|
},
|
|
219
219
|
blockConfigs: [],
|
|
220
220
|
logConfigs: [],
|
|
221
221
|
traceConfigs: [],
|
|
222
|
-
startBlock: aptosProcessor.config.
|
|
222
|
+
startBlock: aptosProcessor.config.startVersion,
|
|
223
223
|
endBlock: DEFAULT_MAX_BLOCK,
|
|
224
224
|
instructionConfig: undefined,
|
|
225
225
|
aptosEventConfigs: [],
|
|
@@ -324,7 +324,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
324
324
|
async processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult> {
|
|
325
325
|
switch (request.handlerType) {
|
|
326
326
|
case HandlerType.APT_CALL:
|
|
327
|
-
return this.
|
|
327
|
+
return this.processAptosFunctionCall(request)
|
|
328
328
|
case HandlerType.APT_EVENT:
|
|
329
329
|
return this.processAptosEvent(request)
|
|
330
330
|
default:
|
|
@@ -410,30 +410,30 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
410
410
|
await Promise.all(processorPromises)
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
413
|
+
// if (request.chainId.toLowerCase().startsWith('apt') && global.PROCESSOR_STATE.aptosProcessors) {
|
|
414
|
+
// const processorPromises: Promise<void>[] = []
|
|
415
|
+
// for (const txn of request.transactions) {
|
|
416
|
+
// processorPromises.push(
|
|
417
|
+
// new Promise((resolve, _) => {
|
|
418
|
+
// for (const processor of global.PROCESSOR_STATE.aptosProcessors) {
|
|
419
|
+
// if (processor.address === txn.programAccountId!) {
|
|
420
|
+
// const res = processor.handleTransaction(
|
|
421
|
+
// JSON.parse(new TextDecoder().decode(txn.raw)),
|
|
422
|
+
// txn.slot ?? Long.fromNumber(0)
|
|
423
|
+
// )
|
|
424
|
+
// if (res) {
|
|
425
|
+
// res.gauges.forEach((g) => result.gauges.push(g))
|
|
426
|
+
// res.counters.forEach((c) => result.counters.push(c))
|
|
427
|
+
// res.logs.forEach((l) => result.logs.push(l))
|
|
428
|
+
// }
|
|
429
|
+
// }
|
|
430
|
+
// }
|
|
431
|
+
// resolve()
|
|
432
|
+
// })
|
|
433
|
+
// )
|
|
434
|
+
// }
|
|
435
|
+
// await Promise.all(processorPromises)
|
|
436
|
+
// }
|
|
437
437
|
|
|
438
438
|
recordRuntimeInfo(result, HandlerType.TRANSACTION)
|
|
439
439
|
return {
|
|
@@ -575,7 +575,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
575
575
|
return result
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
-
async
|
|
578
|
+
async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {
|
|
579
579
|
if (!binding.data) {
|
|
580
580
|
throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
|
|
581
581
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepPartial } from '../gen/builtin'
|
|
2
|
-
import {
|
|
3
|
-
import { Numberish } from '../core'
|
|
2
|
+
import { MetricValue, ProcessResult } from '../gen'
|
|
3
|
+
import { Numberish, BigDecimal } from '../core'
|
|
4
4
|
import { BigNumber } from 'ethers'
|
|
5
5
|
|
|
6
6
|
export function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Numberish | undefined {
|
|
@@ -25,7 +25,7 @@ import { Block, Log } from '@ethersproject/abstract-provider'
|
|
|
25
25
|
import Long from 'long'
|
|
26
26
|
import { getNetwork, Networkish } from '@ethersproject/providers'
|
|
27
27
|
|
|
28
|
-
const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
28
|
+
export const TEST_CONTEXT: CallContext = <CallContext>{}
|
|
29
29
|
|
|
30
30
|
function cleanTest() {
|
|
31
31
|
global.PROCESSOR_STATE = new ProcessorState()
|
|
@@ -238,7 +238,10 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
238
238
|
return binding
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
processBindings(
|
|
241
|
+
processBindings(
|
|
242
|
+
request: ProcessBindingsRequest,
|
|
243
|
+
context: CallContext = TEST_CONTEXT
|
|
244
|
+
): Promise<ProcessBindingResponse> {
|
|
242
245
|
return this.service.processBindings(request, context)
|
|
243
246
|
}
|
|
244
247
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainConfig } from '../chain-config'
|
|
2
2
|
import { CHAIN_MAP } from '../utils/chain'
|
|
3
|
-
import { setProvider } from '
|
|
3
|
+
import { setProvider } from '../provider'
|
|
4
4
|
|
|
5
5
|
export function loadTestProvidersFromEnv(requiredChainIds: string[] | string): boolean {
|
|
6
6
|
const dummyConfig: Record<string, ChainConfig> = {}
|
package/src/tests/aptos.test.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { expect } from 'chai'
|
|
2
|
-
import Long from 'long'
|
|
3
2
|
import { TextEncoder } from 'util'
|
|
4
|
-
import {
|
|
5
|
-
import { chain } from '../utils'
|
|
3
|
+
import { HandlerType, ProcessBindingsRequest } from '..'
|
|
6
4
|
|
|
7
5
|
import { TestProcessorServer } from '../testing'
|
|
8
6
|
|
|
@@ -21,20 +19,57 @@ describe('Test Aptos Example', () => {
|
|
|
21
19
|
})
|
|
22
20
|
|
|
23
21
|
test('Check souffl3 transaction dispatch', async () => {
|
|
24
|
-
const request:
|
|
25
|
-
|
|
26
|
-
transactions: [
|
|
22
|
+
const request: ProcessBindingsRequest = {
|
|
23
|
+
bindings: [
|
|
27
24
|
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
data: {
|
|
26
|
+
raw: new TextEncoder().encode(JSON.stringify(testData)),
|
|
27
|
+
},
|
|
28
|
+
handlerId: 0,
|
|
29
|
+
handlerType: HandlerType.APT_CALL,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
}
|
|
33
|
+
const res = await service.processBindings(request)
|
|
34
|
+
expect(res.result?.counters).length(1)
|
|
35
|
+
expect(res.result?.gauges).length(0)
|
|
36
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('Check souffl3 function call dispatch', async () => {
|
|
40
|
+
const request: ProcessBindingsRequest = {
|
|
41
|
+
bindings: [
|
|
42
|
+
{
|
|
43
|
+
data: {
|
|
44
|
+
raw: new TextEncoder().encode(JSON.stringify(testData)),
|
|
45
|
+
},
|
|
46
|
+
handlerId: 1,
|
|
47
|
+
handlerType: HandlerType.APT_CALL,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
}
|
|
51
|
+
const res = await service.processBindings(request)
|
|
52
|
+
expect(res.result?.counters).length(2)
|
|
53
|
+
expect(res.result?.gauges).length(0)
|
|
54
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('Check souffl3 event dispatch', async () => {
|
|
58
|
+
const request: ProcessBindingsRequest = {
|
|
59
|
+
bindings: [
|
|
60
|
+
{
|
|
61
|
+
data: {
|
|
62
|
+
raw: new TextEncoder().encode(JSON.stringify(testData.events[1])),
|
|
63
|
+
},
|
|
64
|
+
handlerId: 0,
|
|
65
|
+
handlerType: HandlerType.APT_EVENT,
|
|
31
66
|
},
|
|
32
67
|
],
|
|
33
68
|
}
|
|
34
|
-
const res = await service.
|
|
69
|
+
const res = await service.processBindings(request)
|
|
35
70
|
expect(res.result?.counters).length(1)
|
|
36
71
|
expect(res.result?.gauges).length(0)
|
|
37
|
-
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(
|
|
72
|
+
expect(res.result?.counters[0].metadata?.blockNumber.toInt()).equal(18483034)
|
|
38
73
|
})
|
|
39
74
|
})
|
|
40
75
|
|
|
@@ -84,6 +119,7 @@ const testData = {
|
|
|
84
119
|
},
|
|
85
120
|
},
|
|
86
121
|
{
|
|
122
|
+
version: '18483034',
|
|
87
123
|
guid: {
|
|
88
124
|
creation_number: '2',
|
|
89
125
|
account_address: '0x4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
|
package/src/tests/souffl3.ts
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { aptos } from '@sentio/sdk'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
aptos.AptosBaseProcessor.bind({
|
|
4
|
+
name: 'souffl3',
|
|
5
|
+
startVersion: 6604913,
|
|
6
|
+
address: '0x4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
|
|
7
|
+
})
|
|
8
|
+
.onTransaction((txn, ctx) => {
|
|
9
|
+
if (txn.events) {
|
|
10
|
+
for (const event of txn.events) {
|
|
11
|
+
if (event && event.type === '0x3::token::DepositEvent') {
|
|
12
|
+
ctx.meter.Counter('deposit_token_count').add(Number(event.data.amount))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
7
15
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
address: '4188c8694687e844677c2aa87171019e23d61cac60de5082a278a8aa47e9d807',
|
|
15
|
-
}).onTransaction((txn, ctx) => {
|
|
16
|
-
if (txn.events) {
|
|
17
|
-
for (const event of txn.events) {
|
|
18
|
-
if (event && event.type === '0x3::token::DepositEvent') {
|
|
19
|
-
ctx.meter.Counter('deposit_token_count').add(Number(event.data.amount))
|
|
16
|
+
})
|
|
17
|
+
.onEntryFunctionCall(
|
|
18
|
+
(call, ctx) => {
|
|
19
|
+
ctx.meter.Counter('call_num').add(1)
|
|
20
|
+
if (call.arguments.length > 3 && call.type_arguments.length > 0) {
|
|
21
|
+
ctx.meter.Counter('arg').add(parseInt(call.arguments[3]), { type: call.type_arguments[0] })
|
|
20
22
|
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
function: 'SouffleChefCampaign::pull_token_v2',
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
)
|
|
28
|
+
.onEvent(
|
|
29
|
+
(event, ctx) => {
|
|
30
|
+
ctx.meter.Counter('evt_num').add(1)
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: '0x1::coin::DepositEvent',
|
|
34
|
+
}
|
|
35
|
+
)
|
package/src/utils/chain.ts
CHANGED
|
@@ -91,7 +91,9 @@ export const SUI_DEVNET_ID = 'sui_devnet'
|
|
|
91
91
|
CHAIN_MAP[SUI_DEVNET_ID] = 'sui-dev'
|
|
92
92
|
|
|
93
93
|
export const APTOS_TESTNET_ID = 'aptos_testnet'
|
|
94
|
+
export const APTOS_MAINNET_ID = 'aptos_mainnet'
|
|
94
95
|
CHAIN_MAP[APTOS_TESTNET_ID] = 'aptos-test'
|
|
96
|
+
CHAIN_MAP[APTOS_MAINNET_ID] = 'aptos-mainnet'
|
|
95
97
|
|
|
96
98
|
export function getChainName(chainId: string | number): string {
|
|
97
99
|
if (typeof chainId === 'number') {
|