@sentio/sdk 2.12.3 → 2.13.0-rc.10

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 (145) hide show
  1. package/lib/aptos/aptos-chain-adapter.d.ts +14 -0
  2. package/lib/aptos/aptos-chain-adapter.js +69 -0
  3. package/lib/aptos/aptos-chain-adapter.js.map +1 -0
  4. package/lib/aptos/aptos-plugin.js +2 -0
  5. package/lib/aptos/aptos-plugin.js.map +1 -1
  6. package/lib/aptos/aptos-processor.d.ts +7 -7
  7. package/lib/aptos/aptos-processor.js +27 -26
  8. package/lib/aptos/aptos-processor.js.map +1 -1
  9. package/lib/aptos/builtin/0x1.d.ts +1244 -599
  10. package/lib/aptos/builtin/0x1.js +1939 -1458
  11. package/lib/aptos/builtin/0x1.js.map +1 -1
  12. package/lib/aptos/builtin/0x3.d.ts +241 -118
  13. package/lib/aptos/builtin/0x3.js +373 -333
  14. package/lib/aptos/builtin/0x3.js.map +1 -1
  15. package/lib/aptos/codegen/codegen.d.ts +1 -1
  16. package/lib/aptos/codegen/codegen.js +6 -47
  17. package/lib/aptos/codegen/codegen.js.map +1 -1
  18. package/lib/aptos/codegen/run.js +1 -1
  19. package/lib/aptos/codegen/run.js.map +1 -1
  20. package/lib/aptos/context.d.ts +5 -1
  21. package/lib/aptos/context.js +9 -2
  22. package/lib/aptos/context.js.map +1 -1
  23. package/lib/aptos/ext/aptos-dex.d.ts +2 -1
  24. package/lib/aptos/ext/aptos-dex.js +1 -2
  25. package/lib/aptos/ext/aptos-dex.js.map +1 -1
  26. package/lib/aptos/index.d.ts +1 -0
  27. package/lib/aptos/index.js +1 -0
  28. package/lib/aptos/index.js.map +1 -1
  29. package/lib/aptos/models.d.ts +3 -11
  30. package/lib/aptos/models.js.map +1 -1
  31. package/lib/aptos/module-client.js +1 -1
  32. package/lib/aptos/module-client.js.map +1 -1
  33. package/lib/aptos/move-coder.d.ts +10 -10
  34. package/lib/aptos/move-coder.js +37 -18
  35. package/lib/aptos/move-coder.js.map +1 -1
  36. package/lib/eth/base-processor-template.d.ts +4 -3
  37. package/lib/eth/base-processor-template.js +7 -7
  38. package/lib/eth/base-processor-template.js.map +1 -1
  39. package/lib/eth/base-processor.d.ts +9 -8
  40. package/lib/eth/base-processor.js +13 -11
  41. package/lib/eth/base-processor.js.map +1 -1
  42. package/lib/eth/eth-plugin.js +2 -0
  43. package/lib/eth/eth-plugin.js.map +1 -1
  44. package/lib/eth/eth.d.ts +7 -2
  45. package/lib/eth/eth.js +8 -1
  46. package/lib/eth/eth.js.map +1 -1
  47. package/lib/move/abstract-codegen.d.ts +11 -11
  48. package/lib/move/abstract-codegen.js +60 -23
  49. package/lib/move/abstract-codegen.js.map +1 -1
  50. package/lib/move/abstract-move-coder.d.ts +19 -25
  51. package/lib/move/abstract-move-coder.js +74 -51
  52. package/lib/move/abstract-move-coder.js.map +1 -1
  53. package/lib/move/chain-adapter.d.ts +11 -0
  54. package/lib/move/chain-adapter.js +3 -0
  55. package/lib/move/chain-adapter.js.map +1 -0
  56. package/lib/move/index.d.ts +1 -0
  57. package/lib/move/index.js +1 -0
  58. package/lib/move/index.js.map +1 -1
  59. package/lib/move/types.d.ts +28 -1
  60. package/lib/move/types.js +65 -16
  61. package/lib/move/types.js.map +1 -1
  62. package/lib/sui/builtin/0x1.d.ts +37 -18
  63. package/lib/sui/builtin/0x1.js +58 -32
  64. package/lib/sui/builtin/0x1.js.map +1 -1
  65. package/lib/sui/builtin/0x2.d.ts +299 -149
  66. package/lib/sui/builtin/0x2.js +463 -322
  67. package/lib/sui/builtin/0x2.js.map +1 -1
  68. package/lib/sui/builtin/0x3.d.ts +169 -94
  69. package/lib/sui/builtin/0x3.js +229 -272
  70. package/lib/sui/builtin/0x3.js.map +1 -1
  71. package/lib/sui/codegen/codegen.d.ts +1 -1
  72. package/lib/sui/codegen/codegen.js +10 -36
  73. package/lib/sui/codegen/codegen.js.map +1 -1
  74. package/lib/sui/codegen/run.js +1 -1
  75. package/lib/sui/codegen/run.js.map +1 -1
  76. package/lib/sui/context.d.ts +5 -1
  77. package/lib/sui/context.js +8 -1
  78. package/lib/sui/context.js.map +1 -1
  79. package/lib/sui/index.d.ts +1 -0
  80. package/lib/sui/index.js +1 -0
  81. package/lib/sui/index.js.map +1 -1
  82. package/lib/sui/models.d.ts +3 -11
  83. package/lib/sui/models.js.map +1 -1
  84. package/lib/sui/move-coder.d.ts +15 -15
  85. package/lib/sui/move-coder.js +43 -39
  86. package/lib/sui/move-coder.js.map +1 -1
  87. package/lib/sui/sui-chain-adapter.d.ts +14 -0
  88. package/lib/sui/sui-chain-adapter.js +69 -0
  89. package/lib/sui/sui-chain-adapter.js.map +1 -0
  90. package/lib/sui/sui-plugin.js +1 -0
  91. package/lib/sui/sui-plugin.js.map +1 -1
  92. package/lib/sui/sui-processor.d.ts +8 -5
  93. package/lib/sui/sui-processor.js +23 -14
  94. package/lib/sui/sui-processor.js.map +1 -1
  95. package/lib/sui/utils.d.ts +0 -2
  96. package/lib/sui/utils.js +0 -6
  97. package/lib/sui/utils.js.map +1 -1
  98. package/lib/testing/aptos-facet.d.ts +2 -2
  99. package/lib/testing/aptos-facet.js +14 -21
  100. package/lib/testing/aptos-facet.js.map +1 -1
  101. package/lib/testing/sui-facet.d.ts +2 -2
  102. package/lib/testing/sui-facet.js +16 -26
  103. package/lib/testing/sui-facet.js.map +1 -1
  104. package/package.json +4 -4
  105. package/src/aptos/aptos-chain-adapter.ts +81 -0
  106. package/src/aptos/aptos-plugin.ts +2 -0
  107. package/src/aptos/aptos-processor.ts +58 -43
  108. package/src/aptos/builtin/0x1.ts +2858 -616
  109. package/src/aptos/builtin/0x3.ts +543 -120
  110. package/src/aptos/codegen/codegen.ts +13 -57
  111. package/src/aptos/codegen/run.ts +1 -1
  112. package/src/aptos/context.ts +10 -2
  113. package/src/aptos/ext/aptos-dex.ts +4 -12
  114. package/src/aptos/index.ts +2 -0
  115. package/src/aptos/models.ts +3 -13
  116. package/src/aptos/module-client.ts +1 -1
  117. package/src/aptos/move-coder.ts +48 -25
  118. package/src/eth/base-processor-template.ts +20 -10
  119. package/src/eth/base-processor.ts +45 -25
  120. package/src/eth/eth-plugin.ts +2 -0
  121. package/src/eth/eth.ts +15 -2
  122. package/src/move/abstract-codegen.ts +75 -38
  123. package/src/move/abstract-move-coder.ts +87 -75
  124. package/src/move/chain-adapter.ts +17 -0
  125. package/src/move/index.ts +1 -0
  126. package/src/move/types.ts +83 -17
  127. package/src/sui/builtin/0x1.ts +75 -20
  128. package/src/sui/builtin/0x2.ts +694 -150
  129. package/src/sui/builtin/0x3.ts +360 -95
  130. package/src/sui/codegen/codegen.ts +17 -43
  131. package/src/sui/codegen/run.ts +1 -1
  132. package/src/sui/context.ts +9 -1
  133. package/src/sui/index.ts +1 -0
  134. package/src/sui/models.ts +3 -13
  135. package/src/sui/move-coder.ts +58 -53
  136. package/src/sui/sui-chain-adapter.ts +86 -0
  137. package/src/sui/sui-plugin.ts +1 -0
  138. package/src/sui/sui-processor.ts +41 -28
  139. package/src/sui/utils.ts +0 -8
  140. package/src/testing/aptos-facet.ts +13 -27
  141. package/src/testing/sui-facet.ts +15 -30
  142. package/lib/aptos/utils.d.ts +0 -2
  143. package/lib/aptos/utils.js +0 -10
  144. package/lib/aptos/utils.js.map +0 -1
  145. package/src/aptos/utils.ts +0 -11
@@ -0,0 +1,81 @@
1
+ import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'
2
+ import { Event, MoveModuleBytecode, MoveResource, toInternalModule } from './move-types.js'
3
+ import { AptosNetwork } from './network.js'
4
+ import { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'
5
+ import { AptosClient } from 'aptos-sdk'
6
+
7
+ export class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
8
+ static INSTANCE = new AptosChainAdapter()
9
+
10
+ async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {
11
+ const client = getRpcClient(network)
12
+ return await client.getAccountModules(account)
13
+ }
14
+
15
+ async fetchModule(account: string, module: string, network: AptosNetwork): Promise<MoveModuleBytecode> {
16
+ const client = getRpcClient(network)
17
+ return await client.getAccountModule(account, module)
18
+ }
19
+
20
+ toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {
21
+ return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))
22
+ }
23
+
24
+ getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
25
+ if (params.length === 0) {
26
+ return params
27
+ }
28
+ if (params[0].qname === 'signer' && params[0].reference) {
29
+ params = params.slice(1)
30
+ }
31
+ return params
32
+ }
33
+
34
+ getEventStructs(module: InternalMoveModule) {
35
+ const qname = moduleQname(module)
36
+ const structMap = new Map<string, InternalMoveStruct>()
37
+ const eventMap = new Map<string, InternalMoveStruct>()
38
+
39
+ for (const struct of module.structs) {
40
+ structMap.set(qname + SPLITTER + struct.name, struct)
41
+ }
42
+
43
+ for (const struct of module.structs) {
44
+ for (const field of struct.fields) {
45
+ const t = field.type
46
+ if (t.qname === '0x1::event::EventHandle') {
47
+ const event = t.typeArgs[0].qname
48
+ const eventStruct = structMap.get(event)
49
+ if (eventStruct) {
50
+ eventMap.set(event, eventStruct)
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ return eventMap
57
+ }
58
+
59
+ getType(data: Event | MoveResource): string {
60
+ return data.type
61
+ }
62
+
63
+ getData(data: Event | MoveResource) {
64
+ if ('data' in data && 'type' in data) {
65
+ return data.data
66
+ }
67
+ return data
68
+ }
69
+ }
70
+
71
+ function getRpcClient(network: AptosNetwork): AptosClient {
72
+ return new AptosClient(getRpcEndpoint(network))
73
+ }
74
+
75
+ function getRpcEndpoint(network: AptosNetwork): string {
76
+ switch (network) {
77
+ case AptosNetwork.TEST_NET:
78
+ return 'https://testnet.aptoslabs.com/'
79
+ }
80
+ return 'https://mainnet.aptoslabs.com/'
81
+ }
@@ -96,6 +96,7 @@ export class AptosPlugin extends Plugin {
96
96
  minutesInterval: handler.timeIntervalInMinutes,
97
97
  slot: 0,
98
98
  slotInterval: handler.versionInterval,
99
+ fetchConfig: undefined,
99
100
  },
100
101
  type: handler.type || '',
101
102
  })
@@ -107,6 +108,7 @@ export class AptosPlugin extends Plugin {
107
108
  minutesInterval: handler.timeIntervalInMinutes,
108
109
  slot: 0,
109
110
  slotInterval: handler.versionInterval,
111
+ fetchConfig: undefined,
110
112
  },
111
113
  type: handler.type || '',
112
114
  ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,
@@ -1,10 +1,10 @@
1
1
  import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'
2
2
 
3
- import { MOVE_CODER, MoveCoder } from './move-coder.js'
3
+ import { defaultMoveCoder, MoveCoder } from './move-coder.js'
4
4
  import { AptosBindOptions, AptosNetwork, getChainId } from './network.js'
5
5
  import { AptosContext, AptosResourcesContext } from './context.js'
6
6
  import { EventInstance } from './models.js'
7
- import { ListStateStorage } from '@sentio/runtime'
7
+ import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
8
8
  import {
9
9
  MoveFetchConfig,
10
10
  Data_AptResource,
@@ -14,7 +14,13 @@ import {
14
14
  Data_AptCall,
15
15
  } from '@sentio/protos'
16
16
  import { ServerError, Status } from 'nice-grpc'
17
- import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'
17
+ import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'
18
+ import { PromiseOrVoid } from '../core/index.js'
19
+
20
+ const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
21
+ resourceChanges: false,
22
+ allEvents: true,
23
+ }
18
24
 
19
25
  type IndexConfigure = {
20
26
  address: string
@@ -39,12 +45,14 @@ export class AptosBaseProcessor {
39
45
  config: IndexConfigure
40
46
  eventHandlers: EventHandler<Data_AptEvent>[] = []
41
47
  callHandlers: CallHandler<Data_AptCall>[] = []
48
+ coder: MoveCoder
42
49
 
43
50
  constructor(moduleName: string, options: AptosBindOptions) {
44
51
  this.moduleName = moduleName
45
52
  this.config = configure(options)
46
53
  AptosProcessorState.INSTANCE.addValue(this)
47
- this.loadTypes(MOVE_CODER)
54
+ this.coder = defaultMoveCoder(this.config.network)
55
+ // this.loadTypes(this.coder)
48
56
  }
49
57
 
50
58
  // getABI(): MoveModule | undefined {
@@ -52,11 +60,11 @@ export class AptosBaseProcessor {
52
60
  // }
53
61
 
54
62
  public onTransaction(
55
- handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => void,
63
+ handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid,
56
64
  includedFailed = false,
57
- fetchConfig?: MoveFetchConfig
65
+ fetchConfig?: Partial<MoveFetchConfig>
58
66
  ): this {
59
- const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})
67
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
60
68
 
61
69
  // const address = this.config.address
62
70
  // const moduleName = this.moduleName
@@ -72,7 +80,8 @@ export class AptosBaseProcessor {
72
80
  processor.config.network,
73
81
  processor.config.address,
74
82
  BigInt(data.transaction.version),
75
- call
83
+ call,
84
+ 0
76
85
  )
77
86
  await handler(call, ctx)
78
87
  return ctx.getProcessResult()
@@ -86,10 +95,10 @@ export class AptosBaseProcessor {
86
95
  public onMoveEvent(
87
96
  handler: (event: EventInstance, ctx: AptosContext) => void,
88
97
  filter: EventFilter | EventFilter[],
89
- fetchConfig?: MoveFetchConfig
98
+ fetchConfig?: Partial<MoveFetchConfig>
90
99
  ): this {
91
100
  let _filters: EventFilter[] = []
92
- const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})
101
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
93
102
 
94
103
  if (Array.isArray(filter)) {
95
104
  _filters = filter
@@ -97,10 +106,10 @@ export class AptosBaseProcessor {
97
106
  _filters.push(filter)
98
107
  }
99
108
 
100
- // const address = this.config.address
101
109
  // const moduleName = this.moduleName
102
110
 
103
111
  const processor = this
112
+ const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))
104
113
 
105
114
  this.eventHandlers.push({
106
115
  handler: async function (data) {
@@ -112,23 +121,28 @@ export class AptosBaseProcessor {
112
121
  throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')
113
122
  }
114
123
 
115
- const ctx = new AptosContext(
116
- processor.moduleName,
117
- processor.config.network,
118
- processor.config.address,
119
- BigInt(txn.version),
120
- txn
121
- )
122
-
123
- const events = txn.events
124
- txn.events = []
125
- for (const evt of events) {
124
+ const processResults = []
125
+ for (const [idx, evt] of txn.events.entries()) {
126
+ const typeQname = parseMoveType(evt.type).qname
127
+ if (!allEventType.has(typeQname)) {
128
+ continue
129
+ }
130
+
131
+ const ctx = new AptosContext(
132
+ processor.moduleName,
133
+ processor.config.network,
134
+ processor.config.address,
135
+ BigInt(txn.version),
136
+ txn,
137
+ idx
138
+ )
126
139
  const eventInstance = evt as EventInstance
127
- const decoded = MOVE_CODER.decodeEvent<any>(eventInstance)
140
+ const decoded = await processor.coder.decodeEvent<any>(eventInstance)
128
141
  await handler(decoded || eventInstance, ctx)
142
+ processResults.push(ctx.getProcessResult())
129
143
  }
130
144
 
131
- return ctx.getProcessResult()
145
+ return mergeProcessResults(processResults)
132
146
  },
133
147
  filters: _filters,
134
148
  fetchConfig: _fetchConfig,
@@ -137,12 +151,12 @@ export class AptosBaseProcessor {
137
151
  }
138
152
 
139
153
  public onEntryFunctionCall(
140
- handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => void,
154
+ handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid,
141
155
  filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],
142
- fetchConfig?: MoveFetchConfig
156
+ fetchConfig?: Partial<MoveFetchConfig>
143
157
  ): this {
144
158
  let _filters: FunctionNameAndCallFilter[] = []
145
- const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})
159
+ const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
146
160
 
147
161
  if (Array.isArray(filter)) {
148
162
  _filters = filter
@@ -166,11 +180,12 @@ export class AptosBaseProcessor {
166
180
  processor.config.network,
167
181
  processor.config.address,
168
182
  BigInt(tx.version),
169
- tx
183
+ tx,
184
+ 0
170
185
  )
171
186
  if (tx) {
172
187
  const payload = tx.payload as TransactionPayload_EntryFunctionPayload
173
- const decoded = MOVE_CODER.decodeFunctionPayload(payload)
188
+ const decoded = await processor.coder.decodeFunctionPayload(payload)
174
189
  await handler(decoded, ctx)
175
190
  }
176
191
  return ctx.getProcessResult()
@@ -185,17 +200,17 @@ export class AptosBaseProcessor {
185
200
  return getChainId(this.config.network)
186
201
  }
187
202
 
188
- loadTypes(registry: MoveCoder) {
189
- if (registry.contains(this.config.address, this.moduleName)) {
190
- return
191
- }
192
- this.loadTypesInternal(registry)
193
- }
194
-
195
- protected loadTypesInternal(registry: MoveCoder) {
196
- // should be override by subclass
197
- console.log('')
198
- }
203
+ // loadTypes(registry: MoveCoder) {
204
+ // if (registry.contains(this.config.address, this.moduleName)) {
205
+ // return
206
+ // }
207
+ // this.loadTypesInternal(registry)
208
+ // }
209
+ //
210
+ // protected loadTypesInternal(registry: MoveCoder) {
211
+ // // should be override by subclass
212
+ // console.log('')
213
+ // }
199
214
  }
200
215
 
201
216
  export class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {
@@ -221,7 +236,7 @@ export class AptosResourcesProcessor {
221
236
  }
222
237
 
223
238
  private onInterval(
224
- handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,
239
+ handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,
225
240
  timeInterval: HandleInterval | undefined,
226
241
  versionInterval: HandleInterval | undefined,
227
242
  type: string | undefined
@@ -251,7 +266,7 @@ export class AptosResourcesProcessor {
251
266
  }
252
267
 
253
268
  public onTimeInterval(
254
- handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,
269
+ handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,
255
270
  timeIntervalInMinutes = 60,
256
271
  backfillTimeIntervalInMinutes = 240,
257
272
  type?: string
@@ -268,7 +283,7 @@ export class AptosResourcesProcessor {
268
283
  }
269
284
 
270
285
  public onVersionInterval(
271
- handler: (resources: MoveResource[], ctx: AptosResourcesContext) => void,
286
+ handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,
272
287
  versionInterval = 100000,
273
288
  backfillVersionInterval = 400000,
274
289
  typePrefix?: string