@sentio/sdk 2.54.0-rc.6 → 2.54.0-rc.8

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 (48) hide show
  1. package/lib/aptos/builtin/0x1.d.ts +840 -815
  2. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  3. package/lib/aptos/builtin/0x1.js +1200 -1137
  4. package/lib/aptos/builtin/0x1.js.map +1 -1
  5. package/lib/aptos/builtin/0x3.d.ts +67 -52
  6. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  7. package/lib/aptos/builtin/0x3.js +66 -53
  8. package/lib/aptos/builtin/0x3.js.map +1 -1
  9. package/lib/aptos/builtin/0x4.d.ts +113 -113
  10. package/lib/aptos/builtin/0x4.d.ts.map +1 -1
  11. package/lib/aptos/builtin/0x4.js +149 -149
  12. package/lib/aptos/builtin/0x4.js.map +1 -1
  13. package/lib/fuel/fuel-plugin.d.ts +4 -2
  14. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  15. package/lib/fuel/fuel-plugin.js +54 -26
  16. package/lib/fuel/fuel-plugin.js.map +1 -1
  17. package/lib/fuel/fuel-processor.d.ts +3 -2
  18. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  19. package/lib/fuel/fuel-processor.js +19 -24
  20. package/lib/fuel/fuel-processor.js.map +1 -1
  21. package/lib/fuel/transaction.d.ts +5 -1
  22. package/lib/fuel/transaction.d.ts.map +1 -1
  23. package/lib/fuel/transaction.js +17 -10
  24. package/lib/fuel/transaction.js.map +1 -1
  25. package/lib/fuel/types.d.ts +6 -1
  26. package/lib/fuel/types.d.ts.map +1 -1
  27. package/lib/fuel/types.js.map +1 -1
  28. package/lib/sui/builtin/0x1.d.ts +83 -0
  29. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  30. package/lib/sui/builtin/0x1.js +345 -1
  31. package/lib/sui/builtin/0x1.js.map +1 -1
  32. package/lib/testing/fuel-facet.d.ts.map +1 -1
  33. package/lib/testing/fuel-facet.js +8 -7
  34. package/lib/testing/fuel-facet.js.map +1 -1
  35. package/package.json +7 -7
  36. package/src/aptos/abis/0x1.json +3816 -3657
  37. package/src/aptos/abis/0x3.json +247 -219
  38. package/src/aptos/abis/0x4.json +576 -576
  39. package/src/aptos/builtin/0x1.ts +2374 -2235
  40. package/src/aptos/builtin/0x3.ts +154 -113
  41. package/src/aptos/builtin/0x4.ts +280 -282
  42. package/src/fuel/fuel-plugin.ts +62 -25
  43. package/src/fuel/fuel-processor.ts +35 -31
  44. package/src/fuel/transaction.ts +18 -9
  45. package/src/fuel/types.ts +7 -0
  46. package/src/sui/abis/0x1.json +391 -0
  47. package/src/sui/builtin/0x1.ts +510 -1
  48. package/src/testing/fuel-facet.ts +8 -7
@@ -3,6 +3,7 @@ import {
3
3
  ContractConfig,
4
4
  Data_FuelBlock,
5
5
  Data_FuelCall,
6
+ Data_FuelReceipt,
6
7
  DataBinding,
7
8
  HandlerType,
8
9
  ProcessConfigResponse,
@@ -18,21 +19,24 @@ import { FuelProcessor } from './fuel-processor.js'
18
19
  import { FuelGlobalProcessor } from './global-processor.js'
19
20
 
20
21
  interface Handlers {
21
- callHandlers: ((trace: Data_FuelCall) => Promise<ProcessResult>)[]
22
+ transactionHandlers: ((trace: Data_FuelCall) => Promise<ProcessResult>)[]
22
23
  blockHandlers: ((block: Data_FuelBlock) => Promise<ProcessResult>)[]
24
+ logHandlers: ((log: Data_FuelReceipt) => Promise<ProcessResult>)[]
23
25
  }
24
26
 
25
27
  export class FuelPlugin extends Plugin {
26
28
  name: string = 'FuelPlugin'
27
29
  handlers: Handlers = {
28
- callHandlers: [],
29
- blockHandlers: []
30
+ transactionHandlers: [],
31
+ blockHandlers: [],
32
+ logHandlers: []
30
33
  }
31
34
 
32
35
  async configure(config: ProcessConfigResponse) {
33
36
  const handlers: Handlers = {
34
- callHandlers: [],
35
- blockHandlers: []
37
+ transactionHandlers: [],
38
+ blockHandlers: [],
39
+ logHandlers: []
36
40
  }
37
41
 
38
42
  for (const processor of FuelProcessorState.INSTANCE.getValues()) {
@@ -48,23 +52,16 @@ export class FuelPlugin extends Plugin {
48
52
  endBlock: processor.config.endBlock
49
53
  })
50
54
  for (const callHandler of processor.callHandlers) {
51
- const handlerId = handlers.callHandlers.push(callHandler.handler) - 1
55
+ const handlerId = handlers.transactionHandlers.push(callHandler.handler) - 1
52
56
  const handlerName = callHandler.handlerName
53
57
  if (processor instanceof FuelProcessor) {
54
- if (callHandler.logConfig?.logIds?.length) {
55
- contractConfig.fuelLogConfigs.push({
56
- logIds: callHandler.logConfig.logIds,
57
- handlerId,
58
- handlerName
59
- })
60
- } else {
61
- const fetchConfig = {
62
- handlerId,
63
- handlerName,
64
- filters: callHandler.fetchConfig?.filters || []
65
- }
66
- contractConfig.fuelCallConfigs.push(fetchConfig)
58
+ // on transaction
59
+ const fetchConfig = {
60
+ handlerId,
61
+ handlerName,
62
+ filters: callHandler.fetchConfig?.filters || []
67
63
  }
64
+ contractConfig.fuelCallConfigs.push(fetchConfig)
68
65
  } else if (processor instanceof FuelAssetProcessor) {
69
66
  const assetConfig = callHandler.assetConfig
70
67
  contractConfig.assetConfigs.push({
@@ -83,6 +80,18 @@ export class FuelPlugin extends Plugin {
83
80
  }
84
81
  }
85
82
 
83
+ for (const logHandler of processor.logHandlers ?? []) {
84
+ const handlerId = handlers.logHandlers.push(logHandler.handler) - 1
85
+ const handlerName = logHandler.handlerName
86
+ if (processor instanceof FuelProcessor) {
87
+ contractConfig.fuelLogConfigs.push({
88
+ logIds: logHandler.logConfig?.logIds || [],
89
+ handlerId,
90
+ handlerName
91
+ })
92
+ }
93
+ }
94
+
86
95
  for (const blockHandler of processor.blockHandlers) {
87
96
  const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1
88
97
  contractConfig.intervalConfigs.push({
@@ -97,19 +106,25 @@ export class FuelPlugin extends Plugin {
97
106
  })
98
107
  }
99
108
 
100
- // Finish up a contract
101
109
  config.contractConfigs.push(contractConfig)
102
110
  }
103
111
 
104
112
  this.handlers = handlers
105
113
  }
106
114
 
107
- supportedHandlers = [HandlerType.FUEL_CALL, HandlerType.FUEL_BLOCK]
115
+ supportedHandlers = [
116
+ HandlerType.FUEL_TRANSACTION,
117
+ HandlerType.FUEL_RECEIPT,
118
+ HandlerType.FUEL_CALL,
119
+ HandlerType.FUEL_BLOCK
120
+ ]
108
121
 
109
122
  processBinding(request: DataBinding): Promise<ProcessResult> {
110
123
  switch (request.handlerType) {
111
- case HandlerType.FUEL_CALL:
124
+ case HandlerType.FUEL_TRANSACTION:
112
125
  return this.processTransaction(request)
126
+ case HandlerType.FUEL_RECEIPT:
127
+ return this.processLog(request)
113
128
  case HandlerType.FUEL_BLOCK:
114
129
  return this.processBlock(request)
115
130
  default:
@@ -131,16 +146,38 @@ export class FuelPlugin extends Plugin {
131
146
  return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length
132
147
  }
133
148
 
149
+ async processLog(binding: DataBinding): Promise<ProcessResult> {
150
+ if (!binding.data?.fuelLog?.transaction) {
151
+ throw new ServerError(Status.INVALID_ARGUMENT, "transaction can't be null")
152
+ }
153
+ const log = binding.data.fuelLog
154
+
155
+ const promises: Promise<ProcessResult>[] = []
156
+
157
+ for (const handlerId of binding.handlerIds) {
158
+ const promise = this.handlers.logHandlers[handlerId](log).catch((e) => {
159
+ throw new ServerError(
160
+ Status.INTERNAL,
161
+ 'error processing transaction: ' + JSON.stringify(log) + '\n' + errorString(e)
162
+ )
163
+ })
164
+ if (GLOBAL_CONFIG.execution.sequential) {
165
+ await promise
166
+ }
167
+ promises.push(promise)
168
+ }
169
+ return mergeProcessResults(await Promise.all(promises))
170
+ }
134
171
  async processTransaction(binding: DataBinding): Promise<ProcessResult> {
135
- if (!binding.data?.fuelCall?.transaction) {
172
+ if (!binding.data?.fuelTransaction?.transaction) {
136
173
  throw new ServerError(Status.INVALID_ARGUMENT, "transaction can't be null")
137
174
  }
138
- const fuelTransaction = binding.data.fuelCall
175
+ const fuelTransaction = binding.data.fuelTransaction
139
176
 
140
177
  const promises: Promise<ProcessResult>[] = []
141
178
 
142
179
  for (const handlerId of binding.handlerIds) {
143
- const promise = this.handlers.callHandlers[handlerId](fuelTransaction).catch((e) => {
180
+ const promise = this.handlers.transactionHandlers[handlerId](fuelTransaction).catch((e) => {
144
181
  throw new ServerError(
145
182
  Status.INTERNAL,
146
183
  'error processing transaction: ' + JSON.stringify(fuelTransaction.transaction) + '\n' + errorString(e)
@@ -1,8 +1,21 @@
1
- import { Data_FuelBlock, Data_FuelCall, FuelCallFilter, HandleInterval, ProcessResult } from '@sentio/protos'
1
+ import {
2
+ Data_FuelBlock,
3
+ Data_FuelCall,
4
+ Data_FuelReceipt,
5
+ FuelCallFilter,
6
+ HandleInterval,
7
+ ProcessResult
8
+ } from '@sentio/protos'
2
9
  import { FuelCall, FuelContext, FuelContractContext } from './context.js'
3
10
  import { bn, Contract, Interface, JsonAbi, Provider } from 'fuels'
4
11
  import { FuelNetwork, getProvider } from './network.js'
5
- import { decodeFuelTransactionWithAbi, DEFAULT_FUEL_FETCH_CONFIG, FuelFetchConfig } from './transaction.js'
12
+ import {
13
+ decodeFuelTransaction,
14
+ decodeFuelTransactionWithAbi,
15
+ decodeLog,
16
+ DEFAULT_FUEL_FETCH_CONFIG,
17
+ FuelFetchConfig
18
+ } from './transaction.js'
6
19
  import {
7
20
  BlockHandler,
8
21
  CallHandler,
@@ -10,9 +23,9 @@ import {
10
23
  FuelBlock,
11
24
  FuelLog,
12
25
  FuelProcessorState,
13
- FuelTransaction
26
+ FuelTransaction,
27
+ LogHandler
14
28
  } from './types.js'
15
- import { mergeProcessResults } from '@sentio/runtime'
16
29
  import { PromiseOrVoid } from '../core/index.js'
17
30
  import { ServerError, Status } from 'nice-grpc'
18
31
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
@@ -20,6 +33,7 @@ import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
20
33
  export class FuelProcessor<TContract extends Contract> implements FuelBaseProcessor<FuelProcessorConfig> {
21
34
  callHandlers: CallHandler<Data_FuelCall>[] = []
22
35
  blockHandlers: BlockHandler[] = []
36
+ logHandlers: LogHandler<Data_FuelReceipt>[] = []
23
37
 
24
38
  private provider: Provider
25
39
  private contract: TContract
@@ -35,6 +49,7 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
35
49
  }
36
50
 
37
51
  latestGasPrice: string | undefined
52
+
38
53
  async configure() {
39
54
  this.provider = await getProvider(this.config.chainId)
40
55
  this.provider.getLatestGasPrice = async () => {
@@ -169,52 +184,41 @@ export class FuelProcessor<TContract extends Contract> implements FuelBaseProces
169
184
  ) {
170
185
  const logIds = new Set(Array.isArray(logIdFilter) ? logIdFilter : [logIdFilter])
171
186
 
172
- const callHandler = {
187
+ const logHandler = {
173
188
  handlerName: getHandlerName(),
174
- handler: async (call: Data_FuelCall) => {
189
+ handler: async ({ transaction, receiptIndex, timestamp }: Data_FuelReceipt) => {
175
190
  try {
176
- const gqlTransaction = call.transaction
177
- const tx = await decodeFuelTransactionWithAbi(
178
- gqlTransaction,
179
- { [this.config.address]: this.config.abi! },
180
- this.provider
181
- )
182
-
183
- const results: ProcessResult[] = []
184
- const logs = (tx.logs || []).filter((log) => logIds.has(log.logId))
185
- for (const log of logs) {
191
+ const tx = decodeFuelTransaction(transaction, this.provider)
192
+ const index = Number(receiptIndex)
193
+ const receipt = tx.receipts[index]
194
+ const log = decodeLog(receipt, this.config.abi)
195
+ if (log) {
186
196
  const ctx = new FuelContractContext(
187
197
  this.config.chainId,
188
198
  this.contract,
189
199
  this.config.address,
190
200
  this.config.name ?? this.config.address,
191
- call.timestamp || new Date(0),
201
+ timestamp || new Date(0),
192
202
  tx,
193
203
  null
194
204
  )
195
- ctx.setLogIndex(log.receiptIndex)
196
- await handler(log, ctx)
197
- results.push(ctx.stopAndGetResult())
205
+ ctx.setLogIndex(index)
206
+ await handler({ receiptIndex: index, ...log }, ctx)
207
+ return ctx.stopAndGetResult()
208
+ } else {
209
+ console.error(`Log with receipt index ${receiptIndex} not found in tx`)
198
210
  }
199
- return mergeProcessResults(results)
200
211
  } catch (e) {
201
212
  console.error(e)
202
- return {
203
- gauges: [],
204
- counters: [],
205
- events: [],
206
- exports: [],
207
- states: {
208
- configUpdated: false
209
- }
210
- }
211
213
  }
214
+
215
+ return ProcessResult.fromPartial({})
212
216
  },
213
217
  logConfig: {
214
218
  logIds: Array.from(logIds)
215
219
  }
216
220
  }
217
- this.callHandlers.push(callHandler)
221
+ this.logHandlers.push(logHandler)
218
222
  return this
219
223
  }
220
224
 
@@ -7,6 +7,7 @@ import {
7
7
  Input,
8
8
  InputType,
9
9
  Interface,
10
+ JsonAbi,
10
11
  processGqlReceipt,
11
12
  Provider,
12
13
  ReceiptType,
@@ -65,6 +66,17 @@ export function decodeFuelTransaction(gqlTransaction: any, provider: Provider):
65
66
  }
66
67
  }
67
68
 
69
+ export function decodeLog(receipt: any | undefined, abi: JsonAbi) {
70
+ if (receipt && (receipt.type === ReceiptType.LogData || receipt.type === ReceiptType.Log)) {
71
+ const interfaceToUse = new Interface(abi)
72
+ const data = receipt.type === ReceiptType.Log ? new BigNumberCoder('u64').encode(receipt.val0) : receipt.data
73
+ const logId: string = receipt.val1.toString()
74
+ const [decodedLog] = interfaceToUse.decodeLog(data, logId)
75
+ return { logId, data: decodedLog }
76
+ }
77
+ return null
78
+ }
79
+
68
80
  export async function decodeFuelTransactionWithAbi(
69
81
  gqlTransaction: any,
70
82
  abiMap: AbiMap,
@@ -92,16 +104,13 @@ export async function decodeFuelTransactionWithAbi(
92
104
  const abi = Object.values(abiMap)[0]
93
105
  const logs = [] as FuelLog<any>[]
94
106
  ;(receipts as any[]).forEach((receipt, idx) => {
95
- if (receipt.type === ReceiptType.LogData || receipt.type === ReceiptType.Log) {
96
- try {
97
- const interfaceToUse = new Interface(abi)
98
- const data = receipt.type === ReceiptType.Log ? new BigNumberCoder('u64').encode(receipt.val0) : receipt.data
99
- const logId = receipt.val1.toString()
100
- const [decodedLog] = interfaceToUse.decodeLog(data, logId)
101
- logs.push({ logId, data: decodedLog, receiptIndex: idx })
102
- } catch (e) {
103
- console.warn('Failed to decode log', e)
107
+ try {
108
+ const log = decodeLog(receipt, abi)
109
+ if (log) {
110
+ logs.push({ ...log, receiptIndex: idx })
104
111
  }
112
+ } catch (e) {
113
+ console.warn('Failed to decode log', e)
105
114
  }
106
115
  })
107
116
 
package/src/fuel/types.ts CHANGED
@@ -2,6 +2,7 @@ import { MapStateStorage } from '@sentio/runtime'
2
2
  import {
3
3
  Data_FuelBlock,
4
4
  Data_FuelCall,
5
+ Data_FuelReceipt,
5
6
  FuelAssetHandlerConfig,
6
7
  FuelCallHandlerConfig,
7
8
  HandleInterval,
@@ -15,6 +16,7 @@ export interface FuelBaseProcessor<T> {
15
16
  config: T
16
17
  callHandlers: CallHandler<Data_FuelCall>[]
17
18
  blockHandlers: BlockHandler[]
19
+ logHandlers?: LogHandler<Data_FuelReceipt>[]
18
20
  }
19
21
 
20
22
  export class FuelProcessorState extends MapStateStorage<FuelBaseProcessor<any>> {
@@ -26,6 +28,11 @@ export type CallHandler<T> = {
26
28
  handler: (call: T) => Promise<ProcessResult>
27
29
  fetchConfig?: Partial<FuelCallHandlerConfig>
28
30
  assetConfig?: Partial<FuelAssetHandlerConfig>
31
+ }
32
+
33
+ export type LogHandler<T> = {
34
+ handlerName: string
35
+ handler: (call: T) => Promise<ProcessResult>
29
36
  logConfig?: {
30
37
  logIds: string[]
31
38
  }