@sentio/sdk 1.37.0-rc.2 → 1.37.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/lib/builtin/index.d.ts +0 -2
  2. package/lib/builtin/index.js +1 -3
  3. package/lib/builtin/index.js.map +1 -1
  4. package/lib/core/eth-plugin.js +12 -15
  5. package/lib/core/eth-plugin.js.map +1 -1
  6. package/lib/core/index.d.ts +0 -4
  7. package/lib/core/index.js +1 -9
  8. package/lib/core/index.js.map +1 -1
  9. package/lib/core/sui-plugin.js +1 -1
  10. package/lib/core/sui-plugin.js.map +1 -1
  11. package/lib/index.d.ts +1 -1
  12. package/lib/index.js +3 -14
  13. package/lib/index.js.map +1 -1
  14. package/lib/service.d.ts +0 -4
  15. package/lib/service.js +40 -71
  16. package/lib/service.js.map +1 -1
  17. package/package.json +10 -20
  18. package/src/builtin/index.ts +1 -4
  19. package/src/core/eth-plugin.ts +5 -8
  20. package/src/core/index.ts +0 -5
  21. package/src/core/sui-plugin.ts +2 -2
  22. package/src/index.ts +3 -1
  23. package/src/service.ts +13 -71
  24. package/lib/aptos/api.d.ts +0 -2
  25. package/lib/aptos/api.js +0 -14
  26. package/lib/aptos/api.js.map +0 -1
  27. package/lib/aptos/aptos-plugin.d.ts +0 -14
  28. package/lib/aptos/aptos-plugin.js +0 -185
  29. package/lib/aptos/aptos-plugin.js.map +0 -1
  30. package/lib/aptos/aptos-processor.d.ts +0 -75
  31. package/lib/aptos/aptos-processor.js +0 -193
  32. package/lib/aptos/aptos-processor.js.map +0 -1
  33. package/lib/aptos/context.d.ts +0 -22
  34. package/lib/aptos/context.js +0 -65
  35. package/lib/aptos/context.js.map +0 -1
  36. package/lib/aptos/index.d.ts +0 -9
  37. package/lib/aptos/index.js +0 -34
  38. package/lib/aptos/index.js.map +0 -1
  39. package/lib/aptos/models.d.ts +0 -23
  40. package/lib/aptos/models.js +0 -3
  41. package/lib/aptos/models.js.map +0 -1
  42. package/lib/aptos/network.d.ts +0 -14
  43. package/lib/aptos/network.js +0 -46
  44. package/lib/aptos/network.js.map +0 -1
  45. package/lib/aptos/runtime.d.ts +0 -2
  46. package/lib/aptos/runtime.js +0 -16
  47. package/lib/aptos/runtime.js.map +0 -1
  48. package/lib/aptos/type-registry.d.ts +0 -21
  49. package/lib/aptos/type-registry.js +0 -156
  50. package/lib/aptos/type-registry.js.map +0 -1
  51. package/lib/aptos/types.d.ts +0 -9
  52. package/lib/aptos/types.js +0 -135
  53. package/lib/aptos/types.js.map +0 -1
  54. package/lib/aptos/types.test.d.ts +0 -1
  55. package/lib/aptos/types.test.js.map +0 -1
  56. package/lib/aptos/utils.d.ts +0 -7
  57. package/lib/aptos/utils.js +0 -27
  58. package/lib/aptos/utils.js.map +0 -1
  59. package/lib/aptos-codegen/codegen.d.ts +0 -23
  60. package/lib/aptos-codegen/codegen.js +0 -364
  61. package/lib/aptos-codegen/codegen.js.map +0 -1
  62. package/lib/aptos-codegen/typegen.d.ts +0 -17
  63. package/lib/aptos-codegen/typegen.js +0 -142
  64. package/lib/aptos-codegen/typegen.js.map +0 -1
  65. package/lib/builtin/aptos/0x1.d.ts +0 -1913
  66. package/lib/builtin/aptos/0x1.js +0 -2748
  67. package/lib/builtin/aptos/0x1.js.map +0 -1
  68. package/lib/builtin/aptos/0x3.d.ts +0 -482
  69. package/lib/builtin/aptos/0x3.js +0 -526
  70. package/lib/builtin/aptos/0x3.js.map +0 -1
  71. package/lib/builtin/aptos/index.d.ts +0 -2
  72. package/lib/builtin/aptos/index.js +0 -29
  73. package/lib/builtin/aptos/index.js.map +0 -1
  74. package/lib/builtin/solana/index.d.ts +0 -2
  75. package/lib/builtin/solana/index.js +0 -19
  76. package/lib/builtin/solana/index.js.map +0 -1
  77. package/lib/builtin/solana/spl-token-processor.d.ts +0 -39
  78. package/lib/builtin/solana/spl-token-processor.js +0 -258
  79. package/lib/builtin/solana/spl-token-processor.js.map +0 -1
  80. package/lib/builtin/solana/types.d.ts +0 -427
  81. package/lib/builtin/solana/types.js +0 -203
  82. package/lib/builtin/solana/types.js.map +0 -1
  83. package/lib/builtin/solana/wormhole-processor.d.ts +0 -12
  84. package/lib/builtin/solana/wormhole-processor.js +0 -268
  85. package/lib/builtin/solana/wormhole-processor.js.map +0 -1
  86. package/lib/core/solana-context.d.ts +0 -11
  87. package/lib/core/solana-context.js +0 -34
  88. package/lib/core/solana-context.js.map +0 -1
  89. package/lib/core/solana-options.d.ts +0 -8
  90. package/lib/core/solana-options.js +0 -13
  91. package/lib/core/solana-options.js.map +0 -1
  92. package/lib/core/solana-plugin.d.ts +0 -9
  93. package/lib/core/solana-plugin.js +0 -79
  94. package/lib/core/solana-plugin.js.map +0 -1
  95. package/lib/core/solana-processor.d.ts +0 -40
  96. package/lib/core/solana-processor.js +0 -80
  97. package/lib/core/solana-processor.js.map +0 -1
  98. package/lib/solana-codegen/codegen.d.ts +0 -1
  99. package/lib/solana-codegen/codegen.js +0 -124
  100. package/lib/solana-codegen/codegen.js.map +0 -1
  101. package/lib/test-abi-code-gen.d.ts +0 -2
  102. package/lib/test-abi-code-gen.js +0 -20
  103. package/lib/test-abi-code-gen.js.map +0 -1
  104. package/src/abis/aptos/0x1.json +0 -9205
  105. package/src/abis/aptos/0x3.json +0 -1515
  106. package/src/aptos/api.ts +0 -11
  107. package/src/aptos/aptos-plugin.ts +0 -216
  108. package/src/aptos/aptos-processor.ts +0 -305
  109. package/src/aptos/context.ts +0 -74
  110. package/src/aptos/index.ts +0 -10
  111. package/src/aptos/models.ts +0 -34
  112. package/src/aptos/network.ts +0 -42
  113. package/src/aptos/runtime.ts +0 -13
  114. package/src/aptos/type-registry.ts +0 -187
  115. package/src/aptos/types.ts +0 -149
  116. package/src/aptos/utils.ts +0 -26
  117. package/src/aptos-codegen/codegen.ts +0 -428
  118. package/src/aptos-codegen/tsconfig.json +0 -9
  119. package/src/aptos-codegen/typegen.ts +0 -153
  120. package/src/builtin/aptos/0x1.ts +0 -4210
  121. package/src/builtin/aptos/0x3.ts +0 -888
  122. package/src/builtin/aptos/index.ts +0 -2
  123. package/src/builtin/solana/index.ts +0 -2
  124. package/src/builtin/solana/spl-token-processor.ts +0 -298
  125. package/src/builtin/solana/types.ts +0 -279
  126. package/src/builtin/solana/wormhole-processor.ts +0 -269
  127. package/src/core/solana-context.ts +0 -34
  128. package/src/core/solana-options.ts +0 -8
  129. package/src/core/solana-plugin.ts +0 -97
  130. package/src/core/solana-processor.ts +0 -102
  131. package/src/solana-codegen/codegen.ts +0 -129
  132. package/src/test-abi-code-gen.ts +0 -16
package/src/aptos/api.ts DELETED
@@ -1,11 +0,0 @@
1
- import { AptosQueryClient, AptosQueryDefinition } from '@sentio/protos/lib/chainquery/protos/chainquery'
2
- import { createChannel, createClient } from 'nice-grpc'
3
-
4
- export function getChainQueryClient(address?: string): AptosQueryClient {
5
- if (!address) {
6
- address = global.ENDPOINTS.chainQueryAPI
7
- }
8
- const channel = createChannel(address)
9
-
10
- return createClient(AptosQueryDefinition, channel)
11
- }
@@ -1,216 +0,0 @@
1
- import { Plugin, PluginManager } from '@sentio/base'
2
- import {
3
- AccountConfig,
4
- AptosCallHandlerConfig,
5
- AptosEventHandlerConfig,
6
- ContractConfig,
7
- DataBinding,
8
- HandlerType,
9
- ProcessConfigResponse,
10
- ProcessResult,
11
- } from '@sentio/protos'
12
-
13
- import { DEFAULT_MAX_BLOCK, errorString, mergeProcessResults, USER_PROCESSOR, Utf8ArrayToStr } from '../service'
14
-
15
- import { ServerError, Status } from 'nice-grpc'
16
-
17
- import { MoveResource, Transaction_UserTransaction } from 'aptos-sdk/src/generated'
18
- import { AptosAccountProcessorState, AptosProcessorState, MoveResourcesWithVersionPayload } from './aptos-processor'
19
-
20
- export class AptosPlugin implements Plugin {
21
- name: string = 'AptosPlugin'
22
-
23
- private aptosEventHandlers: ((event: any) => Promise<ProcessResult>)[] = []
24
- private aptosCallHandlers: ((func: any) => Promise<ProcessResult>)[] = []
25
- private aptosResourceHandlers: ((resourceWithVersion: MoveResourcesWithVersionPayload) => Promise<ProcessResult>)[] =
26
- []
27
-
28
- configure(config: ProcessConfigResponse): void {
29
- for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
30
- const contractConfig: ContractConfig = {
31
- processorType: USER_PROCESSOR,
32
- contract: {
33
- name: aptosProcessor.moduleName,
34
- chainId: aptosProcessor.getChainId(),
35
- address: aptosProcessor.config.address,
36
- abi: '',
37
- },
38
- intervalConfigs: [],
39
- logConfigs: [],
40
- traceConfigs: [],
41
- startBlock: aptosProcessor.config.startVersion,
42
- endBlock: DEFAULT_MAX_BLOCK,
43
- instructionConfig: undefined,
44
- aptosEventConfigs: [],
45
- aptosCallConfigs: [],
46
- }
47
- // 1. Prepare event handlers
48
- for (const handler of aptosProcessor.eventHandlers) {
49
- const handlerId = this.aptosEventHandlers.push(handler.handler) - 1
50
- const eventHandlerConfig: AptosEventHandlerConfig = {
51
- filters: handler.filters.map((f) => {
52
- return {
53
- type: f.type,
54
- account: f.account || '',
55
- }
56
- }),
57
- handlerId,
58
- }
59
- contractConfig.aptosEventConfigs.push(eventHandlerConfig)
60
- }
61
-
62
- // 2. Prepare function handlers
63
- for (const handler of aptosProcessor.callHandlers) {
64
- const handlerId = this.aptosCallHandlers.push(handler.handler) - 1
65
- const functionHandlerConfig: AptosCallHandlerConfig = {
66
- filters: handler.filters.map((filter) => {
67
- return {
68
- function: filter.function,
69
- typeArguments: filter.typeArguments || [],
70
- withTypeArguments: filter.typeArguments ? true : false,
71
- includeFailed: filter.includeFailed || false,
72
- }
73
- }),
74
- handlerId,
75
- }
76
- contractConfig.aptosCallConfigs.push(functionHandlerConfig)
77
- }
78
- config.contractConfigs.push(contractConfig)
79
- }
80
-
81
- for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {
82
- const accountConfig: AccountConfig = {
83
- address: aptosProcessor.config.address,
84
- chainId: aptosProcessor.getChainId(),
85
- startBlock: aptosProcessor.config.startVersion,
86
- aptosIntervalConfigs: [],
87
- intervalConfigs: [],
88
- logConfigs: [],
89
- }
90
- for (const handler of aptosProcessor.resourcesHandlers) {
91
- const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1
92
- accountConfig.aptosIntervalConfigs.push({
93
- intervalConfig: {
94
- handlerId: handlerId,
95
- minutes: 0,
96
- minutesInterval: handler.timeIntervalInMinutes,
97
- slot: 0,
98
- slotInterval: handler.versionInterval,
99
- },
100
- type: handler.type || '',
101
- })
102
- }
103
- config.accountConfigs.push(accountConfig)
104
- }
105
- }
106
-
107
- supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]
108
-
109
- processBinding(request: DataBinding): Promise<ProcessResult> {
110
- switch (request.handlerType) {
111
- case HandlerType.APT_CALL:
112
- return this.processAptosFunctionCall(request)
113
- case HandlerType.APT_EVENT:
114
- return this.processAptosEvent(request)
115
- case HandlerType.APT_RESOURCE:
116
- return this.processAptosResource(request)
117
- // case HandlerType.INSTRUCTION:
118
- // return this.processInstruction(request)
119
- default:
120
- throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
121
- }
122
- }
123
-
124
- async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {
125
- if (!binding.data) {
126
- throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
127
- }
128
- const promises: Promise<ProcessResult>[] = []
129
- let event: Transaction_UserTransaction
130
- if (binding.data.aptEvent?.event) {
131
- event = binding.data.aptEvent?.event as Transaction_UserTransaction
132
- } else {
133
- const jsonString = Utf8ArrayToStr(binding.data.raw)
134
- event = JSON.parse(jsonString)
135
- }
136
-
137
- for (const handlerId of binding.handlerIds) {
138
- // only support aptos event for now
139
- promises.push(
140
- this.aptosEventHandlers[handlerId](event).catch((e) => {
141
- throw new ServerError(
142
- Status.INTERNAL,
143
- 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
144
- )
145
- })
146
- )
147
- }
148
- return mergeProcessResults(await Promise.all(promises))
149
- }
150
-
151
- async processAptosResource(binding: DataBinding): Promise<ProcessResult> {
152
- if (!binding.data) {
153
- throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
154
- }
155
-
156
- const resource: MoveResourcesWithVersionPayload = {
157
- resources: [],
158
- version: 0n,
159
- timestamp: 0,
160
- }
161
- if (binding.data.aptResource?.resources) {
162
- if (binding.data.aptResource.timestampMicros > Number.MAX_SAFE_INTEGER) {
163
- throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')
164
- }
165
- resource.timestamp = Number(binding.data.aptResource.timestampMicros)
166
- resource.version = binding.data.aptResource.version
167
- resource.resources = binding.data.aptResource.resources as MoveResource[]
168
- } else {
169
- const jsonString = Utf8ArrayToStr(binding.data.raw)
170
- const json = JSON.parse(jsonString)
171
- if (BigInt(json.timestamp) > Number.MAX_SAFE_INTEGER) {
172
- throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')
173
- }
174
- resource.timestamp = parseInt(json.timestamp)
175
- resource.version = BigInt(json.version)
176
- }
177
-
178
- const promises: Promise<ProcessResult>[] = []
179
- for (const handlerId of binding.handlerIds) {
180
- promises.push(
181
- this.aptosResourceHandlers[handlerId](resource).catch((e) => {
182
- throw new ServerError(
183
- Status.INTERNAL,
184
- 'error processing event: ' + JSON.stringify(resource) + '\n' + errorString(e)
185
- )
186
- })
187
- )
188
- }
189
- return mergeProcessResults(await Promise.all(promises))
190
- }
191
-
192
- async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {
193
- if (!binding.data) {
194
- throw new ServerError(Status.INVALID_ARGUMENT, "Event can't be empty")
195
- }
196
- let call: Transaction_UserTransaction
197
- if (binding.data.aptCall?.call) {
198
- call = binding.data.aptCall?.call as Transaction_UserTransaction
199
- } else {
200
- const jsonString = Utf8ArrayToStr(binding.data.raw)
201
- call = JSON.parse(jsonString)
202
- }
203
-
204
- const promises: Promise<ProcessResult>[] = []
205
- for (const handlerId of binding.handlerIds) {
206
- // only support aptos call for now
207
- const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {
208
- throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e))
209
- })
210
- promises.push(promise)
211
- }
212
- return mergeProcessResults(await Promise.all(promises))
213
- }
214
- }
215
-
216
- PluginManager.INSTANCE.register(new AptosPlugin())
@@ -1,305 +0,0 @@
1
- import {
2
- MoveResource,
3
- Transaction_UserTransaction,
4
- TransactionPayload_EntryFunctionPayload,
5
- } from 'aptos-sdk/src/generated'
6
-
7
- import { TYPE_REGISTRY, TypeRegistry } from './type-registry'
8
- import { AptosBindOptions, AptosNetwork, getChainId } from './network'
9
- import { AptosContext, AptosResourceContext } from './context'
10
- import { EventInstance } from './models'
11
- import { ListStateStorage } from '@sentio/base'
12
- import { HandleInterval, ProcessResult } from '@sentio/protos'
13
-
14
- type IndexConfigure = {
15
- address: string
16
- network: AptosNetwork
17
- startVersion: bigint
18
- // endSeqNumber?: Long
19
- }
20
-
21
- // TODO extends ArgumentsFilter
22
- export interface EventFilter {
23
- type: string
24
- account?: string
25
- }
26
-
27
- export interface FunctionNameAndCallFilter extends CallFilter {
28
- function: string
29
- }
30
-
31
- // TODO extends ArgumentsFilter
32
- export interface CallFilter {
33
- includeFailed?: boolean
34
- typeArguments?: string[]
35
- }
36
-
37
- export interface ArgumentsFilter {
38
- arguments?: string[]
39
- }
40
-
41
- class EventHandler {
42
- filters: EventFilter[]
43
- handler: (event: Transaction_UserTransaction) => Promise<ProcessResult>
44
- }
45
-
46
- class CallHandler {
47
- filters: FunctionNameAndCallFilter[]
48
- handler: (call: Transaction_UserTransaction) => Promise<ProcessResult>
49
- }
50
-
51
- export class MoveResourcesWithVersionPayload {
52
- resources: MoveResource[]
53
- version: bigint
54
- timestamp: number
55
- }
56
-
57
- class ResourceHandlder {
58
- type?: string
59
- versionInterval?: HandleInterval
60
- timeIntervalInMinutes?: HandleInterval
61
- handler: (resource: MoveResourcesWithVersionPayload) => Promise<ProcessResult>
62
- }
63
-
64
- export class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {
65
- static INSTANCE = new AptosProcessorState()
66
- }
67
-
68
- export class AptosBaseProcessor {
69
- readonly moduleName: string
70
- config: IndexConfigure
71
- eventHandlers: EventHandler[] = []
72
- callHandlers: CallHandler[] = []
73
-
74
- constructor(moduleName: string, options: AptosBindOptions) {
75
- this.moduleName = moduleName
76
- this.config = configure(options)
77
- AptosProcessorState.INSTANCE.addValue(this)
78
- this.loadTypes(TYPE_REGISTRY)
79
- }
80
-
81
- // getABI(): MoveModule | undefined {
82
- // return undefined
83
- // }
84
-
85
- public onTransaction(
86
- handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void,
87
- includedFailed = false
88
- ): AptosBaseProcessor {
89
- // const address = this.config.address
90
- // const moduleName = this.moduleName
91
- // eslint-disable-next-line @typescript-eslint/no-this-alias
92
- const processor = this
93
- this.callHandlers.push({
94
- handler: async function (tx) {
95
- const ctx = new AptosContext(
96
- processor.moduleName,
97
- processor.config.network,
98
- processor.config.address,
99
- BigInt(tx.version),
100
- tx
101
- )
102
- if (tx) {
103
- await handler(tx, ctx)
104
- }
105
- return ctx.getProcessResult()
106
- },
107
- filters: [{ function: '', includeFailed: includedFailed }],
108
- })
109
- return this
110
- }
111
-
112
- public onEvent(
113
- handler: (event: EventInstance, ctx: AptosContext) => void,
114
- filter: EventFilter | EventFilter[]
115
- ): AptosBaseProcessor {
116
- let _filters: EventFilter[] = []
117
-
118
- if (Array.isArray(filter)) {
119
- _filters = filter
120
- } else {
121
- _filters.push(filter)
122
- }
123
-
124
- // const address = this.config.address
125
- // const moduleName = this.moduleName
126
-
127
- // eslint-disable-next-line @typescript-eslint/no-this-alias
128
- const processor = this
129
-
130
- this.eventHandlers.push({
131
- handler: async function (txn) {
132
- const ctx = new AptosContext(
133
- processor.moduleName,
134
- processor.config.network,
135
- processor.config.address,
136
- BigInt(txn.version),
137
- txn
138
- )
139
- if (txn && txn.events) {
140
- const events = txn.events
141
- txn.events = []
142
- for (const evt of events) {
143
- const eventInstance = evt as EventInstance
144
- const decoded = TYPE_REGISTRY.decodeEvent<any>(eventInstance)
145
- await handler(decoded || eventInstance, ctx)
146
- }
147
- }
148
- return ctx.getProcessResult()
149
- },
150
- filters: _filters,
151
- })
152
- return this
153
- }
154
-
155
- public onEntryFunctionCall(
156
- handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,
157
- filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[]
158
- ): AptosBaseProcessor {
159
- let _filters: FunctionNameAndCallFilter[] = []
160
-
161
- if (Array.isArray(filter)) {
162
- _filters = filter
163
- } else {
164
- _filters.push(filter)
165
- }
166
-
167
- // const address = this.config.address
168
- // const moduleName = this.moduleName
169
- // eslint-disable-next-line @typescript-eslint/no-this-alias
170
- const processor = this
171
-
172
- this.callHandlers.push({
173
- handler: async function (tx) {
174
- const ctx = new AptosContext(
175
- processor.moduleName,
176
- processor.config.network,
177
- processor.config.address,
178
- BigInt(tx.version),
179
- tx
180
- )
181
- if (tx) {
182
- const payload = tx.payload as TransactionPayload_EntryFunctionPayload
183
- const decoded = TYPE_REGISTRY.decodeFunctionPayload(payload)
184
- await handler(decoded, ctx)
185
- }
186
- return ctx.getProcessResult()
187
- },
188
- filters: _filters,
189
- })
190
- return this
191
- }
192
-
193
- getChainId(): string {
194
- return getChainId(this.config.network)
195
- }
196
-
197
- loadTypes(registry: TypeRegistry) {
198
- if (registry.contains(this.config.address, this.moduleName)) {
199
- return
200
- }
201
- this.loadTypesInternal(registry)
202
- }
203
-
204
- protected loadTypesInternal(registry: TypeRegistry) {
205
- // should be override by subclass
206
- console.log('')
207
- }
208
- }
209
-
210
- export class AptosAccountProcessorState extends ListStateStorage<AptosAccountProcessor> {
211
- static INSTANCE = new AptosAccountProcessorState()
212
- }
213
-
214
- export class AptosAccountProcessor {
215
- config: IndexConfigure
216
-
217
- resourcesHandlers: ResourceHandlder[] = []
218
-
219
- static bind(options: AptosBindOptions): AptosAccountProcessor {
220
- return new AptosAccountProcessor(options)
221
- }
222
-
223
- protected constructor(options: AptosBindOptions) {
224
- this.config = configure(options)
225
- AptosAccountProcessorState.INSTANCE.addValue(this)
226
- }
227
-
228
- getChainId(): string {
229
- return getChainId(this.config.network)
230
- }
231
-
232
- private onInterval(
233
- handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
234
- timeInterval: HandleInterval | undefined,
235
- versionInterval: HandleInterval | undefined,
236
- type: string | undefined
237
- ) {
238
- // eslint-disable-next-line @typescript-eslint/no-this-alias
239
- const processor = this
240
- this.resourcesHandlers.push({
241
- handler: async function (arg) {
242
- const ctx = new AptosResourceContext(
243
- processor.config.network,
244
- processor.config.address,
245
- arg.version,
246
- arg.timestamp
247
- )
248
- await handler(arg.resources, ctx)
249
- return ctx.getProcessResult()
250
- },
251
- timeIntervalInMinutes: timeInterval,
252
- versionInterval: versionInterval,
253
- type: type,
254
- })
255
- return this
256
- }
257
-
258
- public onTimeInterval(
259
- handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
260
- timeIntervalInMinutes = 60,
261
- backfillTimeIntervalInMinutes = 240,
262
- type?: string
263
- ) {
264
- return this.onInterval(
265
- handler,
266
- {
267
- recentInterval: timeIntervalInMinutes,
268
- backfillInterval: backfillTimeIntervalInMinutes,
269
- },
270
- undefined,
271
- type
272
- )
273
- }
274
-
275
- public onVersionInterval(
276
- handler: (resources: MoveResource[], ctx: AptosResourceContext) => void,
277
- versionInterval = 100000,
278
- backfillVersionInterval = 400000,
279
- typePrefix?: string
280
- ) {
281
- return this.onInterval(
282
- handler,
283
- undefined,
284
- { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },
285
- typePrefix
286
- )
287
- }
288
- }
289
-
290
- function configure(options: AptosBindOptions): IndexConfigure {
291
- let startVersion = 0n
292
- if (options.startVersion !== undefined) {
293
- if (typeof options.startVersion === 'number') {
294
- startVersion = BigInt(options.startVersion)
295
- } else {
296
- startVersion = options.startVersion
297
- }
298
- }
299
-
300
- return {
301
- startVersion: startVersion,
302
- address: options.address,
303
- network: options.network || AptosNetwork.MAIN_NET,
304
- }
305
- }
@@ -1,74 +0,0 @@
1
- import { RecordMetaData } from '@sentio/protos'
2
- import { Labels } from '../core/metadata'
3
- import { normalizeLabels } from '../core/meter'
4
- import { BaseContext } from '../core/base-context'
5
- import { Transaction_UserTransaction } from 'aptos-sdk/src/generated'
6
- import { AptosNetwork, getChainId } from './network'
7
-
8
- export class AptosContext extends BaseContext {
9
- address: string
10
- network: AptosNetwork
11
- moduleName: string
12
- version: bigint
13
- transaction: Transaction_UserTransaction
14
-
15
- constructor(
16
- moduleName: string,
17
- network: AptosNetwork,
18
- address: string,
19
- version: bigint,
20
- transaction?: Transaction_UserTransaction
21
- ) {
22
- super()
23
- this.address = address
24
- this.network = network
25
- this.moduleName = moduleName
26
- this.version = version
27
- if (transaction) {
28
- this.transaction = transaction
29
- }
30
- }
31
-
32
- getMetaData(name: string, labels: Labels): RecordMetaData {
33
- return {
34
- address: this.address,
35
- contractName: this.moduleName,
36
- blockNumber: this.version,
37
- transactionIndex: 0,
38
- transactionHash: this.transaction?.hash || '', // TODO
39
- logIndex: 0,
40
- chainId: getChainId(this.network),
41
- name: name,
42
- labels: normalizeLabels(labels),
43
- }
44
- }
45
- }
46
-
47
- export class AptosResourceContext extends BaseContext {
48
- address: string
49
- network: AptosNetwork
50
- version: bigint
51
- timestampInMicros: number
52
-
53
- constructor(network: AptosNetwork, address: string, version: bigint, timestampInMicros: number) {
54
- super()
55
- this.address = address
56
- this.network = network
57
- this.version = version
58
- this.timestampInMicros = timestampInMicros
59
- }
60
-
61
- getMetaData(name: string, labels: Labels): RecordMetaData {
62
- return {
63
- address: this.address,
64
- contractName: 'resources',
65
- blockNumber: this.version,
66
- transactionIndex: 0,
67
- transactionHash: '',
68
- logIndex: 0,
69
- chainId: getChainId(this.network),
70
- name: name,
71
- labels: normalizeLabels(labels),
72
- }
73
- }
74
- }
@@ -1,10 +0,0 @@
1
- export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated'
2
- export type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models'
3
- export { TYPE_REGISTRY, TypeRegistry } from './type-registry'
4
- export type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'
5
- export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor'
6
- export { AptosContext, AptosResourceContext } from './context'
7
- export { AptosBindOptions, AptosNetwork, getRpcClient } from './network'
8
- export * from './api'
9
-
10
- export { AptosPlugin } from './aptos-plugin'
@@ -1,34 +0,0 @@
1
- import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated'
2
-
3
- export type EventInstance = Event & {
4
- version: string
5
- }
6
-
7
- export type TypedEventInstance<T> = EventInstance & {
8
- // Typed data converted from ABI
9
- // undefined if there is converting error, usually because the ABI/data
10
- // mismatch
11
- data_typed: T
12
-
13
- type_arguments: string[]
14
- }
15
-
16
- // Don't use intermedidate type to make IDE happier
17
- export type TypedEntryFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
18
- arguments_typed: T
19
- }
20
-
21
- export type TypedMoveResource<T> = MoveResource & {
22
- data_typed: T
23
- type_arguments: string[]
24
- }
25
-
26
- export interface StructWithTag {
27
- type: string
28
- data: any
29
- }
30
-
31
- export interface StructWithType<T> extends StructWithTag {
32
- data_typed: T
33
- type_arguments: string[]
34
- }
@@ -1,42 +0,0 @@
1
- import { CHAIN_IDS, CHAIN_MAP, getChainName } from '../utils/chain'
2
- import { AptosClient } from 'aptos-sdk'
3
-
4
- export enum AptosNetwork {
5
- MAIN_NET = 1,
6
- TEST_NET = 2,
7
- // DEV_NET,
8
- }
9
-
10
- export function getChainId(network: AptosNetwork): string {
11
- switch (network) {
12
- case AptosNetwork.TEST_NET:
13
- return CHAIN_IDS.APTOS_TESTNET
14
- }
15
- return CHAIN_IDS.APTOS_MAINNET
16
- }
17
-
18
- export function getAptosChainName(network: AptosNetwork): string {
19
- switch (network) {
20
- case AptosNetwork.TEST_NET:
21
- return getChainName(CHAIN_IDS.APTOS_TESTNET)
22
- }
23
- return getChainName(CHAIN_IDS.APTOS_MAINNET)
24
- }
25
-
26
- export function getRpcEndpoint(network: AptosNetwork): string {
27
- switch (network) {
28
- case AptosNetwork.TEST_NET:
29
- return 'https://testnet.aptoslabs.com/'
30
- }
31
- return 'https://mainnet.aptoslabs.com/'
32
- }
33
-
34
- export function getRpcClient(network: AptosNetwork): AptosClient {
35
- return new AptosClient(getRpcEndpoint(network))
36
- }
37
-
38
- export class AptosBindOptions {
39
- address: string
40
- network?: AptosNetwork = AptosNetwork.MAIN_NET
41
- startVersion?: bigint | number
42
- }