@sentio/sdk 1.30.2 → 1.31.0
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 +9 -2
- package/lib/aptos/aptos-processor.js +12 -3
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/builtin/erc1155/index.d.ts +2 -0
- package/lib/builtin/erc1155/index.js +22 -0
- package/lib/builtin/erc1155/index.js.map +1 -0
- package/lib/builtin/erc1155/test-utils.d.ts +6 -0
- package/lib/builtin/erc1155/test-utils.js +57 -0
- package/lib/builtin/erc1155/test-utils.js.map +1 -0
- package/lib/builtin/erc721/index.d.ts +2 -0
- package/lib/builtin/erc721/index.js +22 -0
- package/lib/builtin/erc721/index.js.map +1 -0
- package/lib/builtin/erc721/test-utils.d.ts +5 -0
- package/lib/builtin/erc721/test-utils.js +46 -0
- package/lib/builtin/erc721/test-utils.js.map +1 -0
- package/lib/builtin/internal/ERC1155.d.ts +199 -0
- package/lib/builtin/internal/ERC1155.js +3 -0
- package/lib/builtin/internal/ERC1155.js.map +1 -0
- package/lib/builtin/internal/ERC721.d.ts +252 -0
- package/lib/builtin/internal/ERC721.js +3 -0
- package/lib/builtin/internal/ERC721.js.map +1 -0
- package/lib/builtin/internal/erc1155_processor.d.ts +134 -0
- package/lib/builtin/internal/erc1155_processor.js +337 -0
- package/lib/builtin/internal/erc1155_processor.js.map +1 -0
- package/lib/builtin/internal/erc721_processor.d.ts +169 -0
- package/lib/builtin/internal/erc721_processor.js +479 -0
- package/lib/builtin/internal/erc721_processor.js.map +1 -0
- package/lib/builtin/internal/factories/ERC1155__factory.d.ts +35 -0
- package/lib/builtin/internal/factories/ERC1155__factory.js +332 -0
- package/lib/builtin/internal/factories/ERC1155__factory.js.map +1 -0
- package/lib/builtin/internal/factories/ERC721__factory.d.ts +51 -0
- package/lib/builtin/internal/factories/ERC721__factory.js +364 -0
- package/lib/builtin/internal/factories/ERC721__factory.js.map +1 -0
- package/lib/builtin/internal/factories/index.d.ts +2 -0
- package/lib/builtin/internal/factories/index.js +5 -1
- package/lib/builtin/internal/factories/index.js.map +1 -1
- package/lib/builtin/internal/index.d.ts +4 -0
- package/lib/builtin/internal/index.js +5 -1
- package/lib/builtin/internal/index.js.map +1 -1
- package/lib/core/account-processor.d.ts +58 -0
- package/lib/core/account-processor.js +147 -0
- package/lib/core/account-processor.js.map +1 -0
- package/lib/core/base-processor.d.ts +5 -2
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/bind-options.d.ts +5 -0
- package/lib/core/bind-options.js +7 -1
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +7 -1
- package/lib/core/context.js +30 -18
- package/lib/core/context.js.map +1 -1
- package/lib/core/event-tracker.d.ts +5 -1
- package/lib/core/event-tracker.js +8 -5
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/meter.js +6 -0
- package/lib/core/meter.js.map +1 -1
- package/lib/gen/chainquery/protos/chainquery.d.ts +1 -0
- package/lib/gen/chainquery/protos/chainquery.js +17 -1
- package/lib/gen/chainquery/protos/chainquery.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +11 -0
- package/lib/gen/processor/protos/processor.js +84 -3
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/service.d.ts +1 -0
- package/lib/service.js +72 -45
- package/lib/service.js.map +1 -1
- package/lib/state/processor-state.d.ts +1 -5
- package/lib/state/processor-state.js +1 -3
- package/lib/state/processor-state.js.map +1 -1
- package/lib/state/state-storage.d.ts +5 -0
- package/lib/state/state-storage.js +15 -1
- package/lib/state/state-storage.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +6 -2
- package/lib/testing/test-processor-server.js +66 -5
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/utils/price.js +11 -4
- package/lib/utils/price.js.map +1 -1
- package/package.json +1 -1
- package/src/abis/ERC1155.json +314 -0
- package/src/abis/ERC721.json +346 -0
- package/src/aptos/aptos-processor.ts +15 -6
- package/src/builtin/erc1155/index.ts +6 -0
- package/src/builtin/erc1155/test-utils.ts +89 -0
- package/src/builtin/erc721/index.ts +6 -0
- package/src/builtin/erc721/test-utils.ts +71 -0
- package/src/builtin/internal/ERC1155.ts +529 -0
- package/src/builtin/internal/ERC721.ts +639 -0
- package/src/builtin/internal/erc1155_processor.ts +580 -0
- package/src/builtin/internal/erc721_processor.ts +768 -0
- package/src/builtin/internal/factories/ERC1155__factory.ts +335 -0
- package/src/builtin/internal/factories/ERC721__factory.ts +364 -0
- package/src/builtin/internal/factories/index.ts +2 -0
- package/src/builtin/internal/index.ts +4 -0
- package/src/core/account-processor.ts +217 -0
- package/src/core/base-processor.ts +6 -2
- package/src/core/bind-options.ts +6 -0
- package/src/core/context.ts +42 -27
- package/src/core/event-tracker.ts +8 -5
- package/src/core/meter.ts +9 -3
- package/src/gen/chainquery/protos/chainquery.ts +18 -1
- package/src/gen/processor/protos/processor.ts +88 -1
- package/src/index.ts +1 -1
- package/src/service.ts +80 -49
- package/src/state/processor-state.ts +1 -6
- package/src/state/state-storage.ts +16 -0
- package/src/testing/test-processor-server.ts +71 -5
- package/src/utils/price.ts +12 -4
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { ListStateStorage } from '../state/state-storage'
|
|
2
|
+
import { ERC20__factory, ERC721__factory } from '../builtin/internal'
|
|
3
|
+
import { AddressType, DummyProvider, ProcessResult } from '@sentio/sdk'
|
|
4
|
+
import { AccountBindOptions } from './bind-options'
|
|
5
|
+
import { getNetwork } from '@ethersproject/providers'
|
|
6
|
+
import { TransferEvent as ERC20TransferEvent } from '../builtin/internal/ERC20'
|
|
7
|
+
import { TransferEvent as ERC721TransferEvent } from '../builtin/internal/ERC721'
|
|
8
|
+
import { AccountContext } from './context'
|
|
9
|
+
import { PromiseOrVoid } from '../promise-or-void'
|
|
10
|
+
import { Event, EventFilter } from '@ethersproject/contracts'
|
|
11
|
+
import { BytesLike } from '@ethersproject/bytes'
|
|
12
|
+
import { AddressOrTypeEventFilter, EventsHandler } from './base-processor'
|
|
13
|
+
|
|
14
|
+
export class AccountProcessorState extends ListStateStorage<AccountProcessor> {
|
|
15
|
+
static INSTANCE = new AccountProcessorState()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const ERC20_CONTRACT = ERC20__factory.connect('', DummyProvider)
|
|
19
|
+
const ERC721_CONTRACT = ERC721__factory.connect('', DummyProvider)
|
|
20
|
+
|
|
21
|
+
export class AccountProcessor {
|
|
22
|
+
config: AccountBindOptions
|
|
23
|
+
eventHandlers: EventsHandler[] = []
|
|
24
|
+
|
|
25
|
+
static bind(config: AccountBindOptions): AccountProcessor {
|
|
26
|
+
const processor = new AccountProcessor(config)
|
|
27
|
+
AccountProcessorState.INSTANCE.addValue(processor)
|
|
28
|
+
return processor
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected constructor(config: AccountBindOptions) {
|
|
32
|
+
this.config = config
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public getChainId(): number {
|
|
36
|
+
return getNetwork(this.config.network || 1).chainId
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Register custom handler function to process erc20 transfer event to this account
|
|
41
|
+
* @param handler custom handler function
|
|
42
|
+
* @param tokensAddresses all the erc20 token address to watch
|
|
43
|
+
*/
|
|
44
|
+
onERC20TransferIn(
|
|
45
|
+
handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
46
|
+
tokensAddresses: string[] = []
|
|
47
|
+
) {
|
|
48
|
+
return this.onERC20(handler, tokensAddresses, (address: string) =>
|
|
49
|
+
ERC20_CONTRACT.filters.Transfer(null, this.config.address)
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Register custom handler function to process erc20 transfer event from this account
|
|
55
|
+
* @param handler custom handler function
|
|
56
|
+
* @param tokensAddresses all the erc20 token address to watch
|
|
57
|
+
*/
|
|
58
|
+
onERC20TransferOut(
|
|
59
|
+
handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
60
|
+
tokensAddresses: string[] = []
|
|
61
|
+
) {
|
|
62
|
+
return this.onERC20(handler, tokensAddresses, (address: string) =>
|
|
63
|
+
ERC20_CONTRACT.filters.Transfer(this.config.address)
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Register custom handler function to process erc20 mint for this account
|
|
69
|
+
* @param handler custom handler function
|
|
70
|
+
* @param tokensAddresses all the erc20 token address to watch
|
|
71
|
+
*/
|
|
72
|
+
onERC20Minted(
|
|
73
|
+
handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
74
|
+
tokensAddresses: string[] = []
|
|
75
|
+
) {
|
|
76
|
+
return this.onERC20(handler, tokensAddresses, (address: string) =>
|
|
77
|
+
ERC20_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address)
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private onERC20(
|
|
82
|
+
handler: (event: ERC20TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
83
|
+
tokensAddresses: string[] = [],
|
|
84
|
+
defaultFilter: (address: string) => AddressOrTypeEventFilter
|
|
85
|
+
) {
|
|
86
|
+
return this.onERC(handler, tokensAddresses, defaultFilter, AddressType.ERC20)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Register custom handler function to process ERC721 transfer event to this account
|
|
91
|
+
* @param handler custom handler function
|
|
92
|
+
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
|
93
|
+
*/
|
|
94
|
+
onERC721TransferIn(
|
|
95
|
+
handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
96
|
+
collections: string[]
|
|
97
|
+
) {
|
|
98
|
+
return this.onERC721(handler, collections, (address: string) =>
|
|
99
|
+
ERC721_CONTRACT.filters.Transfer(null, this.config.address)
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Register custom handler function to process ERC721 transfer event from this account
|
|
105
|
+
* @param handler custom handler function
|
|
106
|
+
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
|
107
|
+
*/
|
|
108
|
+
onERC721TransferOut(
|
|
109
|
+
handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
110
|
+
collections: string[]
|
|
111
|
+
) {
|
|
112
|
+
return this.onERC721(handler, collections, (address: string) =>
|
|
113
|
+
ERC721_CONTRACT.filters.Transfer(this.config.address)
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Register custom handler function to process ERC721 mint for this account
|
|
119
|
+
* @param handler custom handler function
|
|
120
|
+
* @param collections all the ERC721 token address to watch, if not provided then watch all ERC721
|
|
121
|
+
*/
|
|
122
|
+
onERC721Minted(
|
|
123
|
+
handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
124
|
+
collections: string[] = []
|
|
125
|
+
) {
|
|
126
|
+
return this.onERC721(handler, collections, (address: string) =>
|
|
127
|
+
ERC721_CONTRACT.filters.Transfer('0x0000000000000000000000000000000000000000', this.config.address)
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private onERC721(
|
|
132
|
+
handler: (event: ERC721TransferEvent, ctx: AccountContext) => PromiseOrVoid,
|
|
133
|
+
collections: string[],
|
|
134
|
+
defaultFilter: (address: string) => AddressOrTypeEventFilter
|
|
135
|
+
) {
|
|
136
|
+
return this.onERC(handler, collections, defaultFilter, AddressType.ERC721)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private onERC(
|
|
140
|
+
handler: (event: any, ctx: AccountContext) => PromiseOrVoid,
|
|
141
|
+
contractAddresses: string[],
|
|
142
|
+
defaultFilter: (address: string) => AddressOrTypeEventFilter,
|
|
143
|
+
addressType: AddressType
|
|
144
|
+
) {
|
|
145
|
+
const filters = []
|
|
146
|
+
for (const token of contractAddresses) {
|
|
147
|
+
const filter = defaultFilter(this.config.address)
|
|
148
|
+
filter.address = token
|
|
149
|
+
filters.push(filter)
|
|
150
|
+
}
|
|
151
|
+
if (!filters.length) {
|
|
152
|
+
const filter = defaultFilter(this.config.address)
|
|
153
|
+
filter.address = undefined
|
|
154
|
+
filter.addressType = addressType
|
|
155
|
+
filters.push(filter)
|
|
156
|
+
}
|
|
157
|
+
return this.onEvent(handler, filters)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
protected onEvent(
|
|
161
|
+
handler: (event: Event, ctx: AccountContext) => PromiseOrVoid,
|
|
162
|
+
filter: AddressOrTypeEventFilter | AddressOrTypeEventFilter[]
|
|
163
|
+
) {
|
|
164
|
+
const chainId = this.getChainId()
|
|
165
|
+
|
|
166
|
+
let _filters: AddressOrTypeEventFilter[] = []
|
|
167
|
+
|
|
168
|
+
if (Array.isArray(filter)) {
|
|
169
|
+
_filters = filter
|
|
170
|
+
} else {
|
|
171
|
+
_filters.push(filter)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let hasVaildConfig = false
|
|
175
|
+
for (const filter of _filters) {
|
|
176
|
+
if (filter.address) {
|
|
177
|
+
hasVaildConfig = true
|
|
178
|
+
break
|
|
179
|
+
}
|
|
180
|
+
if (filter.topics && filter.topics.length) {
|
|
181
|
+
hasVaildConfig = true
|
|
182
|
+
break
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (!hasVaildConfig) {
|
|
187
|
+
throw Error('no valid config has been found for this account')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const config = this.config
|
|
191
|
+
|
|
192
|
+
this.eventHandlers.push({
|
|
193
|
+
filters: _filters,
|
|
194
|
+
handler: async function (log) {
|
|
195
|
+
const ctx = new AccountContext(chainId, config.address, undefined, log)
|
|
196
|
+
// let event: Event = <Event>deepCopy(log);
|
|
197
|
+
const event: Event = <Event>log
|
|
198
|
+
const parsed = ERC20_CONTRACT.interface.parseLog(log)
|
|
199
|
+
if (parsed) {
|
|
200
|
+
event.args = parsed.args
|
|
201
|
+
event.decode = (data: BytesLike, topics?: Array<any>) => {
|
|
202
|
+
return ERC20_CONTRACT.interface.decodeEventLog(parsed.eventFragment, data, topics)
|
|
203
|
+
}
|
|
204
|
+
event.event = parsed.name
|
|
205
|
+
event.eventSignature = parsed.signature
|
|
206
|
+
|
|
207
|
+
// TODO fix this bug
|
|
208
|
+
await handler(event, ctx)
|
|
209
|
+
return ctx.getProcessResult()
|
|
210
|
+
}
|
|
211
|
+
return ProcessResult.fromPartial({})
|
|
212
|
+
},
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
return this
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -4,13 +4,17 @@ import { BaseContract, Event, EventFilter } from '@ethersproject/contracts'
|
|
|
4
4
|
import Long from 'long'
|
|
5
5
|
|
|
6
6
|
import { BoundContractView, ContractContext, ContractView } from './context'
|
|
7
|
-
import { ProcessResult } from '../gen'
|
|
7
|
+
import { AddressType, ProcessResult } from '../gen'
|
|
8
8
|
import { BindInternalOptions, BindOptions } from './bind-options'
|
|
9
9
|
import { PromiseOrVoid } from '../promise-or-void'
|
|
10
10
|
import { Trace } from './trace'
|
|
11
11
|
|
|
12
|
+
export interface AddressOrTypeEventFilter extends EventFilter {
|
|
13
|
+
addressType?: AddressType
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
export class EventsHandler {
|
|
13
|
-
filters:
|
|
17
|
+
filters: AddressOrTypeEventFilter[]
|
|
14
18
|
handler: (event: Log) => Promise<ProcessResult>
|
|
15
19
|
}
|
|
16
20
|
|
package/src/core/bind-options.ts
CHANGED
package/src/core/context.ts
CHANGED
|
@@ -34,34 +34,14 @@ export abstract class EthContext extends BaseContext {
|
|
|
34
34
|
this.transactionHash = trace.transactionHash
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
}
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
TContract extends BaseContract,
|
|
41
|
-
TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>
|
|
42
|
-
> extends EthContext {
|
|
43
|
-
contract: TContractBoundView
|
|
44
|
-
contractName: string
|
|
45
|
-
|
|
46
|
-
constructor(
|
|
47
|
-
contractName: string,
|
|
48
|
-
view: TContractBoundView,
|
|
49
|
-
chainId: number,
|
|
50
|
-
block?: Block,
|
|
51
|
-
log?: Log,
|
|
52
|
-
trace?: Trace
|
|
53
|
-
) {
|
|
54
|
-
super(chainId, view.rawContract.address, block, log, trace)
|
|
55
|
-
view.context = this
|
|
56
|
-
this.contractName = contractName
|
|
57
|
-
this.contract = view
|
|
58
|
-
}
|
|
38
|
+
protected abstract getContractName(): string
|
|
59
39
|
|
|
60
40
|
getMetaData(name: string, labels: Labels): RecordMetaData {
|
|
61
41
|
if (this.log) {
|
|
62
42
|
return {
|
|
63
|
-
address: this.
|
|
64
|
-
contractName: this.
|
|
43
|
+
address: this.address,
|
|
44
|
+
contractName: this.getContractName(),
|
|
65
45
|
blockNumber: this.blockNumber,
|
|
66
46
|
transactionIndex: this.log.transactionIndex,
|
|
67
47
|
transactionHash: this.transactionHash || '',
|
|
@@ -74,8 +54,8 @@ export class ContractContext<
|
|
|
74
54
|
}
|
|
75
55
|
if (this.block) {
|
|
76
56
|
return {
|
|
77
|
-
address: this.
|
|
78
|
-
contractName: this.
|
|
57
|
+
address: this.address,
|
|
58
|
+
contractName: this.getContractName(),
|
|
79
59
|
blockNumber: this.blockNumber,
|
|
80
60
|
transactionIndex: -1,
|
|
81
61
|
transactionHash: '',
|
|
@@ -88,8 +68,8 @@ export class ContractContext<
|
|
|
88
68
|
}
|
|
89
69
|
if (this.trace) {
|
|
90
70
|
return {
|
|
91
|
-
address: this.
|
|
92
|
-
contractName: this.
|
|
71
|
+
address: this.address,
|
|
72
|
+
contractName: this.getContractName(),
|
|
93
73
|
blockNumber: this.blockNumber,
|
|
94
74
|
transactionIndex: this.trace.transactionPosition,
|
|
95
75
|
transactionHash: this.transactionHash || '',
|
|
@@ -104,6 +84,41 @@ export class ContractContext<
|
|
|
104
84
|
}
|
|
105
85
|
}
|
|
106
86
|
|
|
87
|
+
export class AccountContext extends EthContext {
|
|
88
|
+
constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {
|
|
89
|
+
super(chainId, address, block, log, trace)
|
|
90
|
+
}
|
|
91
|
+
protected getContractName(): string {
|
|
92
|
+
return 'account'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class ContractContext<
|
|
97
|
+
TContract extends BaseContract,
|
|
98
|
+
TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>
|
|
99
|
+
> extends EthContext {
|
|
100
|
+
contract: TContractBoundView
|
|
101
|
+
contractName: string
|
|
102
|
+
|
|
103
|
+
constructor(
|
|
104
|
+
contractName: string,
|
|
105
|
+
view: TContractBoundView,
|
|
106
|
+
chainId: number,
|
|
107
|
+
block?: Block,
|
|
108
|
+
log?: Log,
|
|
109
|
+
trace?: Trace
|
|
110
|
+
) {
|
|
111
|
+
super(chainId, view.rawContract.address, block, log, trace)
|
|
112
|
+
view.context = this
|
|
113
|
+
this.contractName = contractName
|
|
114
|
+
this.contract = view
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected getContractName(): string {
|
|
118
|
+
return this.contractName
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
107
122
|
export class ContractView<TContract extends BaseContract> {
|
|
108
123
|
filters: { [name: string]: (...args: Array<any>) => EventFilter }
|
|
109
124
|
protected contract: TContract
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseContext } from './base-context'
|
|
2
|
-
import {
|
|
2
|
+
import { EventTrackingResult } from '../gen'
|
|
3
3
|
import { NamedResultDescriptor } from './metadata'
|
|
4
|
+
import { MapStateStorage } from '../state/state-storage'
|
|
4
5
|
|
|
5
6
|
export interface Event {
|
|
6
7
|
// The unique identifier of main identity associate with an event
|
|
@@ -16,6 +17,10 @@ export interface TrackerOptions {
|
|
|
16
17
|
distinctByDays?: number[]
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
export class EventTrackerState extends MapStateStorage<EventTracker> {
|
|
21
|
+
static INSTANCE = new EventTrackerState()
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
// Track Event with an identity associate with it
|
|
20
25
|
export class EventTracker extends NamedResultDescriptor {
|
|
21
26
|
static DEFAULT_OPTIONS: TrackerOptions = {
|
|
@@ -25,8 +30,7 @@ export class EventTracker extends NamedResultDescriptor {
|
|
|
25
30
|
|
|
26
31
|
static register(eventName: string, options?: TrackerOptions) {
|
|
27
32
|
const tracker = new EventTracker(eventName, { ...EventTracker.DEFAULT_OPTIONS, ...options })
|
|
28
|
-
|
|
29
|
-
return tracker
|
|
33
|
+
return EventTrackerState.INSTANCE.getOrSetValue(eventName, tracker)
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
options: TrackerOptions
|
|
@@ -60,7 +64,6 @@ export class AccountEventTracker extends EventTracker {
|
|
|
60
64
|
eventName = 'user'
|
|
61
65
|
}
|
|
62
66
|
const tracker = new AccountEventTracker(eventName, { ...AccountEventTracker.DEFAULT_OPTIONS, ...options })
|
|
63
|
-
|
|
64
|
-
return tracker
|
|
67
|
+
return EventTrackerState.INSTANCE.getOrSetValue(eventName, tracker)
|
|
65
68
|
}
|
|
66
69
|
}
|
package/src/core/meter.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseContext } from './base-context'
|
|
2
|
-
import {
|
|
2
|
+
import { Numberish, toMetricValue } from './numberish'
|
|
3
3
|
import { Labels, NamedResultDescriptor } from './metadata'
|
|
4
|
-
import { AggregationConfig, MetricConfig } from '../gen'
|
|
5
|
-
import { MapStateStorage
|
|
4
|
+
import { AggregationConfig, AggregationType, MetricConfig } from '../gen'
|
|
5
|
+
import { MapStateStorage } from '../state/state-storage'
|
|
6
6
|
|
|
7
7
|
export function normalizeName(name: string): string {
|
|
8
8
|
const regex = new RegExp('![_.a-zA-Z0-9]')
|
|
@@ -53,6 +53,12 @@ export class Metric extends NamedResultDescriptor {
|
|
|
53
53
|
super(name)
|
|
54
54
|
this.type = type
|
|
55
55
|
this.descriptor = MetricConfig.fromPartial({ name: this.name, ...option })
|
|
56
|
+
const aggregationConfig = this.descriptor.aggregationConfig
|
|
57
|
+
if (aggregationConfig) {
|
|
58
|
+
if (aggregationConfig.intervalInMinutes > 0 && !aggregationConfig.types) {
|
|
59
|
+
aggregationConfig.types = [AggregationType.SUM, AggregationType.COUNT]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
|
|
@@ -16,6 +16,7 @@ export interface AptosGetTxnsByVersionRequest {
|
|
|
16
16
|
network: string;
|
|
17
17
|
fromVersion: Long;
|
|
18
18
|
toVersion: Long;
|
|
19
|
+
headerOnly?: boolean | undefined;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export interface AptosGetTxnsByEventRequest {
|
|
@@ -175,7 +176,12 @@ export const AptosGetTxnsByFunctionRequest = {
|
|
|
175
176
|
};
|
|
176
177
|
|
|
177
178
|
function createBaseAptosGetTxnsByVersionRequest(): AptosGetTxnsByVersionRequest {
|
|
178
|
-
return {
|
|
179
|
+
return {
|
|
180
|
+
network: "",
|
|
181
|
+
fromVersion: Long.UZERO,
|
|
182
|
+
toVersion: Long.UZERO,
|
|
183
|
+
headerOnly: undefined,
|
|
184
|
+
};
|
|
179
185
|
}
|
|
180
186
|
|
|
181
187
|
export const AptosGetTxnsByVersionRequest = {
|
|
@@ -192,6 +198,9 @@ export const AptosGetTxnsByVersionRequest = {
|
|
|
192
198
|
if (!message.toVersion.isZero()) {
|
|
193
199
|
writer.uint32(24).uint64(message.toVersion);
|
|
194
200
|
}
|
|
201
|
+
if (message.headerOnly !== undefined) {
|
|
202
|
+
writer.uint32(32).bool(message.headerOnly);
|
|
203
|
+
}
|
|
195
204
|
return writer;
|
|
196
205
|
},
|
|
197
206
|
|
|
@@ -214,6 +223,9 @@ export const AptosGetTxnsByVersionRequest = {
|
|
|
214
223
|
case 3:
|
|
215
224
|
message.toVersion = reader.uint64() as Long;
|
|
216
225
|
break;
|
|
226
|
+
case 4:
|
|
227
|
+
message.headerOnly = reader.bool();
|
|
228
|
+
break;
|
|
217
229
|
default:
|
|
218
230
|
reader.skipType(tag & 7);
|
|
219
231
|
break;
|
|
@@ -231,6 +243,9 @@ export const AptosGetTxnsByVersionRequest = {
|
|
|
231
243
|
toVersion: isSet(object.toVersion)
|
|
232
244
|
? Long.fromValue(object.toVersion)
|
|
233
245
|
: Long.UZERO,
|
|
246
|
+
headerOnly: isSet(object.headerOnly)
|
|
247
|
+
? Boolean(object.headerOnly)
|
|
248
|
+
: undefined,
|
|
234
249
|
};
|
|
235
250
|
},
|
|
236
251
|
|
|
@@ -241,6 +256,7 @@ export const AptosGetTxnsByVersionRequest = {
|
|
|
241
256
|
(obj.fromVersion = (message.fromVersion || Long.UZERO).toString());
|
|
242
257
|
message.toVersion !== undefined &&
|
|
243
258
|
(obj.toVersion = (message.toVersion || Long.UZERO).toString());
|
|
259
|
+
message.headerOnly !== undefined && (obj.headerOnly = message.headerOnly);
|
|
244
260
|
return obj;
|
|
245
261
|
},
|
|
246
262
|
|
|
@@ -257,6 +273,7 @@ export const AptosGetTxnsByVersionRequest = {
|
|
|
257
273
|
object.toVersion !== undefined && object.toVersion !== null
|
|
258
274
|
? Long.fromValue(object.toVersion)
|
|
259
275
|
: Long.UZERO;
|
|
276
|
+
message.headerOnly = object.headerOnly ?? undefined;
|
|
260
277
|
return message;
|
|
261
278
|
},
|
|
262
279
|
};
|
|
@@ -37,6 +37,45 @@ export function aggregationTypeToJSON(object: AggregationType): string {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export enum AddressType {
|
|
41
|
+
ERC20 = 0,
|
|
42
|
+
ERC721 = 1,
|
|
43
|
+
ERC1155 = 2,
|
|
44
|
+
UNRECOGNIZED = -1,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function addressTypeFromJSON(object: any): AddressType {
|
|
48
|
+
switch (object) {
|
|
49
|
+
case 0:
|
|
50
|
+
case "ERC20":
|
|
51
|
+
return AddressType.ERC20;
|
|
52
|
+
case 1:
|
|
53
|
+
case "ERC721":
|
|
54
|
+
return AddressType.ERC721;
|
|
55
|
+
case 2:
|
|
56
|
+
case "ERC1155":
|
|
57
|
+
return AddressType.ERC1155;
|
|
58
|
+
case -1:
|
|
59
|
+
case "UNRECOGNIZED":
|
|
60
|
+
default:
|
|
61
|
+
return AddressType.UNRECOGNIZED;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function addressTypeToJSON(object: AddressType): string {
|
|
66
|
+
switch (object) {
|
|
67
|
+
case AddressType.ERC20:
|
|
68
|
+
return "ERC20";
|
|
69
|
+
case AddressType.ERC721:
|
|
70
|
+
return "ERC721";
|
|
71
|
+
case AddressType.ERC1155:
|
|
72
|
+
return "ERC1155";
|
|
73
|
+
case AddressType.UNRECOGNIZED:
|
|
74
|
+
default:
|
|
75
|
+
return "UNRECOGNIZED";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
40
79
|
export enum HandlerType {
|
|
41
80
|
UNKNOWN = 0,
|
|
42
81
|
ETH_LOG = 1,
|
|
@@ -273,6 +312,7 @@ export interface AccountConfig {
|
|
|
273
312
|
startBlock: Long;
|
|
274
313
|
intervalConfigs: OnIntervalConfig[];
|
|
275
314
|
aptosIntervalConfigs: AptosOnIntervalConfig[];
|
|
315
|
+
logConfigs: LogHandlerConfig[];
|
|
276
316
|
}
|
|
277
317
|
|
|
278
318
|
export interface OnIntervalConfig {
|
|
@@ -320,6 +360,8 @@ export interface LogHandlerConfig {
|
|
|
320
360
|
|
|
321
361
|
export interface LogFilter {
|
|
322
362
|
topics: Topic[];
|
|
363
|
+
address: string | undefined;
|
|
364
|
+
addressType: AddressType | undefined;
|
|
323
365
|
}
|
|
324
366
|
|
|
325
367
|
export interface InstructionHandlerConfig {
|
|
@@ -1607,6 +1649,7 @@ function createBaseAccountConfig(): AccountConfig {
|
|
|
1607
1649
|
startBlock: Long.UZERO,
|
|
1608
1650
|
intervalConfigs: [],
|
|
1609
1651
|
aptosIntervalConfigs: [],
|
|
1652
|
+
logConfigs: [],
|
|
1610
1653
|
};
|
|
1611
1654
|
}
|
|
1612
1655
|
|
|
@@ -1630,6 +1673,9 @@ export const AccountConfig = {
|
|
|
1630
1673
|
for (const v of message.aptosIntervalConfigs) {
|
|
1631
1674
|
AptosOnIntervalConfig.encode(v!, writer.uint32(42).fork()).ldelim();
|
|
1632
1675
|
}
|
|
1676
|
+
for (const v of message.logConfigs) {
|
|
1677
|
+
LogHandlerConfig.encode(v!, writer.uint32(50).fork()).ldelim();
|
|
1678
|
+
}
|
|
1633
1679
|
return writer;
|
|
1634
1680
|
},
|
|
1635
1681
|
|
|
@@ -1659,6 +1705,11 @@ export const AccountConfig = {
|
|
|
1659
1705
|
AptosOnIntervalConfig.decode(reader, reader.uint32())
|
|
1660
1706
|
);
|
|
1661
1707
|
break;
|
|
1708
|
+
case 6:
|
|
1709
|
+
message.logConfigs.push(
|
|
1710
|
+
LogHandlerConfig.decode(reader, reader.uint32())
|
|
1711
|
+
);
|
|
1712
|
+
break;
|
|
1662
1713
|
default:
|
|
1663
1714
|
reader.skipType(tag & 7);
|
|
1664
1715
|
break;
|
|
@@ -1682,6 +1733,9 @@ export const AccountConfig = {
|
|
|
1682
1733
|
AptosOnIntervalConfig.fromJSON(e)
|
|
1683
1734
|
)
|
|
1684
1735
|
: [],
|
|
1736
|
+
logConfigs: Array.isArray(object?.logConfigs)
|
|
1737
|
+
? object.logConfigs.map((e: any) => LogHandlerConfig.fromJSON(e))
|
|
1738
|
+
: [],
|
|
1685
1739
|
};
|
|
1686
1740
|
},
|
|
1687
1741
|
|
|
@@ -1705,6 +1759,13 @@ export const AccountConfig = {
|
|
|
1705
1759
|
} else {
|
|
1706
1760
|
obj.aptosIntervalConfigs = [];
|
|
1707
1761
|
}
|
|
1762
|
+
if (message.logConfigs) {
|
|
1763
|
+
obj.logConfigs = message.logConfigs.map((e) =>
|
|
1764
|
+
e ? LogHandlerConfig.toJSON(e) : undefined
|
|
1765
|
+
);
|
|
1766
|
+
} else {
|
|
1767
|
+
obj.logConfigs = [];
|
|
1768
|
+
}
|
|
1708
1769
|
return obj;
|
|
1709
1770
|
},
|
|
1710
1771
|
|
|
@@ -1722,6 +1783,8 @@ export const AccountConfig = {
|
|
|
1722
1783
|
object.aptosIntervalConfigs?.map((e) =>
|
|
1723
1784
|
AptosOnIntervalConfig.fromPartial(e)
|
|
1724
1785
|
) || [];
|
|
1786
|
+
message.logConfigs =
|
|
1787
|
+
object.logConfigs?.map((e) => LogHandlerConfig.fromPartial(e)) || [];
|
|
1725
1788
|
return message;
|
|
1726
1789
|
},
|
|
1727
1790
|
};
|
|
@@ -2313,7 +2376,7 @@ export const LogHandlerConfig = {
|
|
|
2313
2376
|
};
|
|
2314
2377
|
|
|
2315
2378
|
function createBaseLogFilter(): LogFilter {
|
|
2316
|
-
return { topics: [] };
|
|
2379
|
+
return { topics: [], address: undefined, addressType: undefined };
|
|
2317
2380
|
}
|
|
2318
2381
|
|
|
2319
2382
|
export const LogFilter = {
|
|
@@ -2324,6 +2387,12 @@ export const LogFilter = {
|
|
|
2324
2387
|
for (const v of message.topics) {
|
|
2325
2388
|
Topic.encode(v!, writer.uint32(10).fork()).ldelim();
|
|
2326
2389
|
}
|
|
2390
|
+
if (message.address !== undefined) {
|
|
2391
|
+
writer.uint32(18).string(message.address);
|
|
2392
|
+
}
|
|
2393
|
+
if (message.addressType !== undefined) {
|
|
2394
|
+
writer.uint32(24).int32(message.addressType);
|
|
2395
|
+
}
|
|
2327
2396
|
return writer;
|
|
2328
2397
|
},
|
|
2329
2398
|
|
|
@@ -2337,6 +2406,12 @@ export const LogFilter = {
|
|
|
2337
2406
|
case 1:
|
|
2338
2407
|
message.topics.push(Topic.decode(reader, reader.uint32()));
|
|
2339
2408
|
break;
|
|
2409
|
+
case 2:
|
|
2410
|
+
message.address = reader.string();
|
|
2411
|
+
break;
|
|
2412
|
+
case 3:
|
|
2413
|
+
message.addressType = reader.int32() as any;
|
|
2414
|
+
break;
|
|
2340
2415
|
default:
|
|
2341
2416
|
reader.skipType(tag & 7);
|
|
2342
2417
|
break;
|
|
@@ -2350,6 +2425,10 @@ export const LogFilter = {
|
|
|
2350
2425
|
topics: Array.isArray(object?.topics)
|
|
2351
2426
|
? object.topics.map((e: any) => Topic.fromJSON(e))
|
|
2352
2427
|
: [],
|
|
2428
|
+
address: isSet(object.address) ? String(object.address) : undefined,
|
|
2429
|
+
addressType: isSet(object.addressType)
|
|
2430
|
+
? addressTypeFromJSON(object.addressType)
|
|
2431
|
+
: undefined,
|
|
2353
2432
|
};
|
|
2354
2433
|
},
|
|
2355
2434
|
|
|
@@ -2360,12 +2439,20 @@ export const LogFilter = {
|
|
|
2360
2439
|
} else {
|
|
2361
2440
|
obj.topics = [];
|
|
2362
2441
|
}
|
|
2442
|
+
message.address !== undefined && (obj.address = message.address);
|
|
2443
|
+
message.addressType !== undefined &&
|
|
2444
|
+
(obj.addressType =
|
|
2445
|
+
message.addressType !== undefined
|
|
2446
|
+
? addressTypeToJSON(message.addressType)
|
|
2447
|
+
: undefined);
|
|
2363
2448
|
return obj;
|
|
2364
2449
|
},
|
|
2365
2450
|
|
|
2366
2451
|
fromPartial(object: DeepPartial<LogFilter>): LogFilter {
|
|
2367
2452
|
const message = createBaseLogFilter();
|
|
2368
2453
|
message.topics = object.topics?.map((e) => Topic.fromPartial(e)) || [];
|
|
2454
|
+
message.address = object.address ?? undefined;
|
|
2455
|
+
message.addressType = object.addressType ?? undefined;
|
|
2369
2456
|
return message;
|
|
2370
2457
|
},
|
|
2371
2458
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ProcessorServiceImpl } from './service'
|
|
1
|
+
// export { ProcessorServiceImpl } from './service'
|
|
2
2
|
export { getProvider, setProvider, DummyProvider } from './provider'
|
|
3
3
|
export { transformEtherError } from './error'
|
|
4
4
|
// export { ProcessorState } from './state/processor-state'
|