@sentio/sdk 2.36.0-rc.9 → 2.36.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.
Files changed (86) hide show
  1. package/lib/aptos/builtin/0x1.js +1 -1
  2. package/lib/aptos/builtin/0x1.js.map +1 -1
  3. package/lib/aptos/builtin/0x3.js +1 -1
  4. package/lib/aptos/builtin/0x3.js.map +1 -1
  5. package/lib/aptos/builtin/0x4.js +1 -1
  6. package/lib/aptos/builtin/0x4.js.map +1 -1
  7. package/lib/core/big-decimal.d.ts +6 -0
  8. package/lib/core/big-decimal.d.ts.map +1 -1
  9. package/lib/core/big-decimal.js +7 -0
  10. package/lib/core/big-decimal.js.map +1 -1
  11. package/lib/core/event-logger.d.ts +3 -1
  12. package/lib/core/event-logger.d.ts.map +1 -1
  13. package/lib/core/event-logger.js.map +1 -1
  14. package/lib/core/normalization.d.ts.map +1 -1
  15. package/lib/core/normalization.js +4 -0
  16. package/lib/core/normalization.js.map +1 -1
  17. package/lib/fuel/asset-processor.d.ts.map +1 -1
  18. package/lib/fuel/asset-processor.js +1 -2
  19. package/lib/fuel/asset-processor.js.map +1 -1
  20. package/lib/fuel/base-processor.d.ts +8 -6
  21. package/lib/fuel/base-processor.d.ts.map +1 -1
  22. package/lib/fuel/base-processor.js +11 -9
  23. package/lib/fuel/base-processor.js.map +1 -1
  24. package/lib/fuel/codegen/codegen.js +86 -18
  25. package/lib/fuel/codegen/codegen.js.map +1 -1
  26. package/lib/fuel/codegen/utils.d.ts.map +1 -1
  27. package/lib/fuel/codegen/utils.js.map +1 -1
  28. package/lib/fuel/context.d.ts +10 -2
  29. package/lib/fuel/context.d.ts.map +1 -1
  30. package/lib/fuel/context.js +15 -1
  31. package/lib/fuel/context.js.map +1 -1
  32. package/lib/fuel/fuel-plugin.d.ts.map +1 -1
  33. package/lib/fuel/fuel-plugin.js +23 -5
  34. package/lib/fuel/fuel-plugin.js.map +1 -1
  35. package/lib/fuel/fuel-processor.d.ts +3 -2
  36. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  37. package/lib/fuel/fuel-processor.js +27 -6
  38. package/lib/fuel/fuel-processor.js.map +1 -1
  39. package/lib/fuel/global-processor.d.ts +17 -0
  40. package/lib/fuel/global-processor.d.ts.map +1 -0
  41. package/lib/fuel/global-processor.js +39 -0
  42. package/lib/fuel/global-processor.js.map +1 -0
  43. package/lib/fuel/index.d.ts +1 -0
  44. package/lib/fuel/index.d.ts.map +1 -1
  45. package/lib/fuel/index.js +1 -0
  46. package/lib/fuel/index.js.map +1 -1
  47. package/lib/fuel/network.js +1 -1
  48. package/lib/fuel/network.js.map +1 -1
  49. package/lib/fuel/transaction.d.ts +4 -1
  50. package/lib/fuel/transaction.d.ts.map +1 -1
  51. package/lib/fuel/transaction.js +25 -6
  52. package/lib/fuel/transaction.js.map +1 -1
  53. package/lib/fuel/types.d.ts +8 -0
  54. package/lib/fuel/types.d.ts.map +1 -1
  55. package/lib/sui/builtin/0x1.js +1 -1
  56. package/lib/sui/builtin/0x1.js.map +1 -1
  57. package/lib/sui/builtin/0x2.js +1 -1
  58. package/lib/sui/builtin/0x2.js.map +1 -1
  59. package/lib/sui/builtin/0x3.js +1 -1
  60. package/lib/sui/builtin/0x3.js.map +1 -1
  61. package/lib/testing/fuel-facet.d.ts.map +1 -1
  62. package/lib/testing/fuel-facet.js +18 -0
  63. package/lib/testing/fuel-facet.js.map +1 -1
  64. package/package.json +20 -24
  65. package/src/aptos/builtin/0x1.ts +1 -1
  66. package/src/aptos/builtin/0x3.ts +1 -1
  67. package/src/aptos/builtin/0x4.ts +1 -1
  68. package/src/core/big-decimal.ts +17 -0
  69. package/src/core/event-logger.ts +6 -1
  70. package/src/core/normalization.ts +4 -0
  71. package/src/fuel/asset-processor.ts +1 -2
  72. package/src/fuel/base-processor.ts +13 -23
  73. package/src/fuel/codegen/codegen.ts +85 -12
  74. package/src/fuel/codegen/utils.ts +2 -5
  75. package/src/fuel/context.ts +20 -3
  76. package/src/fuel/fuel-plugin.ts +20 -4
  77. package/src/fuel/fuel-processor.ts +44 -7
  78. package/src/fuel/global-processor.ts +48 -0
  79. package/src/fuel/index.ts +1 -0
  80. package/src/fuel/network.ts +1 -1
  81. package/src/fuel/transaction.ts +48 -6
  82. package/src/fuel/types.ts +9 -0
  83. package/src/sui/builtin/0x1.ts +1 -1
  84. package/src/sui/builtin/0x2.ts +1 -1
  85. package/src/sui/builtin/0x3.ts +1 -1
  86. package/src/testing/fuel-facet.ts +21 -0
@@ -15,8 +15,9 @@ export async function codegen(abisDir: string, outDir: string) {
15
15
  }
16
16
 
17
17
  function patchImport(contents: string) {
18
- return contents
19
- .replace(
18
+ return (
19
+ contents
20
+ /* .replace(
20
21
  `import { Interface, Contract, ContractFactory } from "fuels";`,
21
22
  `import { Contract, } from "@fuel-ts/program";
22
23
  import { ContractFactory } from "@fuel-ts/contract";
@@ -29,8 +30,9 @@ import { Interface } from "@fuel-ts/abi-coder";`
29
30
  import type { AbstractAddress, BytesLike } from "@fuel-ts/interfaces";
30
31
  import type { DeployContractOptions } from "@fuel-ts/contract";
31
32
  import type { StorageSlot } from "@fuel-ts/transactions";`
32
- )
33
- .replace(/from\s+['"](\..+)['"]/g, `from '\$1.js'`)
33
+ )*/
34
+ .replace(/from\s+['"](\..+)['"]/g, `from '\$1.js'`)
35
+ )
34
36
  }
35
37
 
36
38
  function patchEnumType(contents: string) {
@@ -90,26 +92,68 @@ async function codegenInternal(abisDir: string, outDir: string): Promise<number>
90
92
  }
91
93
  })
92
94
 
95
+ // for (const file of abiTypeGen.files) {
96
+ // const jsonAbi: JsonAbi = JSON.parse(file.contents)
97
+ // for (const logType of jsonAbi.loggedTypes) {
98
+ // logType.loggedType.name
99
+ //
100
+ // }
101
+ // }
102
+
93
103
  for (const abi of abiTypeGen.abis) {
94
104
  const name = abi.name.endsWith('Abi') ? abi.name.slice(0, -3) : abi.name
95
105
  const filePath = path.join(outDir, `${name}Processor.ts`)
96
106
  const importedTypes = collectImportedTypes(abi.types)
97
107
 
108
+ const logByTypes: Record<string, string[]> = {}
109
+
110
+ for (const logType of abi.rawContents.loggedTypes) {
111
+ // @ts-ignore - we know that the type is in the abi
112
+ const t = abi.types.find((t) => t.rawAbiType.typeId == logType.loggedType?.type)
113
+ // @ts-ignore - we know that the type is in the abi
114
+ const typeName = t?.attributes?.outputLabel
115
+ if (typeName) {
116
+ if (!logByTypes[typeName]) {
117
+ logByTypes[typeName] = []
118
+ }
119
+ logByTypes[typeName].push(logType.logId)
120
+ }
121
+ }
122
+
98
123
  const content = `/* Autogenerated file. Do not edit manually. */
99
124
 
100
125
  /* tslint:disable */
101
126
  /* eslint-disable */
102
127
 
103
- import { FuelAbstractProcessor, FuelContext, FuelProcessorConfig, TypedCall, FuelFetchConfig} from '@sentio/sdk/fuel'
128
+ import { FuelAbstractProcessor, FuelContext, FuelProcessorConfig, TypedCall, FuelFetchConfig, FuelCall, FuelLog} from '@sentio/sdk/fuel'
104
129
  import {${abi.name}__factory } from './factories/${abi.name}__factory.js'
105
130
  import {${abi.commonTypesInUse.join(',')}} from './common.js'
106
131
  import {${importedTypes.join(',')}} from './${abi.name}.js'
107
132
 
108
- import type { BigNumberish, BN } from '@fuel-ts/math';
109
- import type { BytesLike } from '@fuel-ts/interfaces';
133
+ import type { BigNumberish, BN } from 'fuels';
134
+ import type { BytesLike } from 'fuels';
110
135
 
111
136
 
112
137
  namespace ${name} {
138
+ export abstract class CallWithLogs<T extends Array<any>, R> extends TypedCall<T, R> {
139
+ ${Object.entries(logByTypes)
140
+ .flatMap(([t, ids]) => {
141
+ const s = ids.map(
142
+ (id) => `
143
+ getLog${id}(): Array<${t}> {
144
+ return this.logs?.filter(l => l.logId == ${id})?.map(l => l.data) as Array<${t}>
145
+ }`
146
+ )
147
+ s.push(`
148
+ getLogsOfType${getTypeName(t)}(): Array<${t}> {
149
+ return this.logs?.filter(l =>[${ids.join(', ')}].includes(l.logId) ).map(l => l.data) as Array<${t}>
150
+ }`)
151
+
152
+ return s
153
+ })
154
+ .join('\n')}
155
+ }
156
+
113
157
  ${abi.functions.map(genCallType).join('\n')}
114
158
  }
115
159
 
@@ -126,6 +170,9 @@ export class ${name}Processor extends FuelAbstractProcessor {
126
170
  }
127
171
 
128
172
  ${abi.functions.map((f) => genOnCallFunction(name, f)).join('\n')}
173
+
174
+ ${Object.entries(logByTypes).map(genOnLogFunction).join('\n')}
175
+
129
176
  }
130
177
  `
131
178
  writeFileSync(filePath, content)
@@ -137,10 +184,24 @@ ${abi.functions.map((f) => genOnCallFunction(name, f)).join('\n')}
137
184
 
138
185
  function genCallType(f: IFunction) {
139
186
  const name = upperFirst(f.name)
187
+ const argMap: Record<string, string> = {}
188
+ const argTypes = f.attributes.inputs.split(',').map((t) => t.trim())
189
+ f.rawAbiFunction.inputs.forEach((input, idx) => {
190
+ argMap[input.name] = argTypes[idx]
191
+ })
192
+
140
193
  return `
141
- export interface ${name}Call extends TypedCall<[${f.attributes.inputs}], ${f.attributes.output}> {
142
- args: [${f.attributes.inputs}]
143
- returnValue: ${f.attributes.output}
194
+ export class ${name}Call extends CallWithLogs<[${argTypes.join(', ')}], ${f.attributes.output}> {
195
+ declare args: [${argTypes.join(', ')}]
196
+ declare returnValue: ${f.attributes.output}
197
+ declare argsObject: {
198
+ ${Object.entries(argMap)
199
+ .map(([k, v]) => `${k}: ${v}`)
200
+ .join(', ')}
201
+ }
202
+ constructor(call: FuelCall) {
203
+ super(call)
204
+ }
144
205
  }
145
206
  `
146
207
  }
@@ -148,8 +209,8 @@ function genCallType(f: IFunction) {
148
209
  function genOnCallFunction(contractName: string, f: IFunction) {
149
210
  const name = upperFirst(f.name)
150
211
  return `
151
- onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContext) => void | Promise<void>, config: FuelFetchConfig) {
152
- super.onCallMethod('${f.name}', handler, config)
212
+ onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContext) => void | Promise<void>, config?: FuelFetchConfig) {
213
+ return super.onCall('${f.name}', (call, ctx) => handler(new ${contractName}.${name}Call(call), ctx), config)
153
214
  }`
154
215
  }
155
216
 
@@ -164,3 +225,15 @@ function collectImportedTypes(types: any[]): string[] {
164
225
 
165
226
  return Array.from(ret)
166
227
  }
228
+
229
+ function genOnLogFunction([type, ids]: [string, string[]]) {
230
+ const name = getTypeName(type)
231
+ return `
232
+ onLog${name}(handler: (log: FuelLog<${type}>, ctx: FuelContext) => void | Promise<void>, logIdFilter?: number | number[]) {
233
+ return super.onLog<${type}>(logIdFilter ?? [${ids.join(', ')}], (log, ctx) => handler(log, ctx))
234
+ }`
235
+ }
236
+
237
+ function getTypeName(type: string) {
238
+ return upperFirst(type.replace('Output', ''))
239
+ }
@@ -1,6 +1,3 @@
1
-
2
-
3
-
4
1
  export function upperFirst(str: string): string {
5
- return str.charAt(0).toUpperCase() + str.slice(1);
6
- }
2
+ return str.charAt(0).toUpperCase() + str.slice(1)
3
+ }
@@ -1,12 +1,25 @@
1
1
  import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
2
2
  import { ChainId } from '@sentio/chain'
3
3
  import { RecordMetaData } from '@sentio/protos'
4
- import { InvocationCallResult } from '@fuel-ts/program'
4
+ import type { CallResult } from 'fuels'
5
+ import { InvocationCallResult, InvocationScopeLike } from 'fuels'
5
6
  import { FuelTransaction } from './transaction.js'
7
+ import { FuelLog } from './types.js'
6
8
 
7
- export type FuelCall = InvocationCallResult
9
+ export class FuelCall extends InvocationCallResult {
10
+ constructor(
11
+ funcScopes: InvocationScopeLike | Array<InvocationScopeLike>,
12
+ callResult: CallResult,
13
+ isMultiCall: boolean,
14
+ readonly args?: Record<string, any>,
15
+ readonly logs?: FuelLog<unknown>[]
16
+ ) {
17
+ super(funcScopes, callResult, isMultiCall)
18
+ }
19
+ }
8
20
 
9
21
  export class FuelContext extends BaseContext {
22
+ private logIndex: number = -1
10
23
  constructor(
11
24
  readonly chainId: ChainId,
12
25
  readonly contractAddress: string,
@@ -20,6 +33,10 @@ export class FuelContext extends BaseContext {
20
33
  return this.chainId
21
34
  }
22
35
 
36
+ setLogIndex(logIndex: number): void {
37
+ this.logIndex = logIndex
38
+ }
39
+
23
40
  protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
24
41
  return {
25
42
  address: this.contractAddress,
@@ -29,7 +46,7 @@ export class FuelContext extends BaseContext {
29
46
  transactionHash: this.transaction?.id || '', // TODO
30
47
  chainId: this.getChainId(),
31
48
  name: name,
32
- logIndex: -1,
49
+ logIndex: this.logIndex,
33
50
  labels: normalizeLabels(labels)
34
51
  }
35
52
  }
@@ -14,6 +14,8 @@ import { TemplateInstanceState } from '../core/template.js'
14
14
  import { FuelAssetProcessor } from './asset-processor.js'
15
15
  import { FuelProcessorState } from './types.js'
16
16
  import { FuelProcessor } from './fuel-processor.js'
17
+ import { BN } from 'fuels'
18
+ import { FuelGlobalProcessor } from './global-processor.js'
17
19
 
18
20
  interface Handlers {
19
21
  callHandlers: ((trace: Data_FuelCall) => Promise<ProcessResult>)[]
@@ -46,17 +48,31 @@ export class FuelPlugin extends Plugin {
46
48
  for (const callHandler of processor.callHandlers) {
47
49
  const handlerId = handlers.callHandlers.push(callHandler.handler) - 1
48
50
  if (processor instanceof FuelProcessor) {
49
- const fetchConfig = {
50
- handlerId,
51
- filters: callHandler.fetchConfig?.filters || []
51
+ if (callHandler.logConfig?.logIds?.length) {
52
+ contractConfig.fuelLogConfigs.push({
53
+ logIds: callHandler.logConfig.logIds.map((logId) => new BN(logId).toString(10)),
54
+ handlerId
55
+ })
56
+ } else {
57
+ const fetchConfig = {
58
+ handlerId,
59
+ filters: callHandler.fetchConfig?.filters || []
60
+ }
61
+ contractConfig.fuelCallConfigs.push(fetchConfig)
52
62
  }
53
- contractConfig.fuelCallConfigs.push(fetchConfig)
54
63
  } else if (processor instanceof FuelAssetProcessor) {
55
64
  const assetConfig = callHandler.assetConfig
56
65
  contractConfig.assetConfigs.push({
57
66
  filters: assetConfig?.filters || [],
58
67
  handlerId
59
68
  })
69
+ } else if (processor instanceof FuelGlobalProcessor) {
70
+ const fetchConfig = {
71
+ handlerId,
72
+ filters: []
73
+ }
74
+ contractConfig.fuelCallConfigs.push(fetchConfig)
75
+ contractConfig.contract!.address = '*'
60
76
  }
61
77
  }
62
78
 
@@ -1,9 +1,6 @@
1
- import { Data_FuelCall, FuelCallFilter } from '@sentio/protos'
1
+ import { Data_FuelCall, FuelCallFilter, ProcessResult } from '@sentio/protos'
2
2
  import { FuelCall, FuelContext } from './context.js'
3
- import { Provider } from '@fuel-ts/account'
4
- import { Contract, InvocationCallResult } from '@fuel-ts/program'
5
- import { Interface, JsonAbi } from '@fuel-ts/abi-coder'
6
- import { bn } from '@fuel-ts/math'
3
+ import { bn, Contract, Interface, JsonAbi, Provider } from 'fuels'
7
4
  import { FuelNetwork, getRpcEndpoint } from './network.js'
8
5
  import {
9
6
  decodeFuelTransactionWithAbi,
@@ -11,7 +8,8 @@ import {
11
8
  FuelFetchConfig,
12
9
  FuelTransaction
13
10
  } from './transaction.js'
14
- import { CallHandler, FuelBaseProcessor, FuelProcessorState } from './types.js'
11
+ import { CallHandler, FuelBaseProcessor, FuelLog, FuelProcessorState } from './types.js'
12
+ import { mergeProcessResults } from '@sentio/runtime'
15
13
 
16
14
  export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
17
15
  callHandlers: CallHandler<Data_FuelCall>[] = []
@@ -107,7 +105,8 @@ export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
107
105
  const fn = contract.functions[call.functionName]
108
106
  const args = Object.values(call.argumentsProvided || {})
109
107
  const scope = fn(...args)
110
- const invocationResult = await InvocationCallResult.build(scope, tx, false)
108
+ const invocationResult = new FuelCall(scope, tx, false, call.argumentsProvided, tx.logs)
109
+
111
110
  await handler(invocationResult, ctx)
112
111
  }
113
112
  }
@@ -122,6 +121,44 @@ export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
122
121
  this.callHandlers.push(callHandler)
123
122
  return this
124
123
  }
124
+
125
+ public onLog<T>(
126
+ logIdFilter: number | number[],
127
+ handler: (logs: FuelLog<T>, ctx: FuelContext) => void | Promise<void>
128
+ ) {
129
+ const logIds = new Set(Array.isArray(logIdFilter) ? logIdFilter : [logIdFilter])
130
+
131
+ const callHandler = {
132
+ handler: async (call: Data_FuelCall) => {
133
+ const gqlTransaction = call.transaction
134
+ const tx = decodeFuelTransactionWithAbi(
135
+ gqlTransaction,
136
+ { [this.config.address]: this.config.abi! },
137
+ this.provider
138
+ )
139
+
140
+ const results: ProcessResult[] = []
141
+ const logs = (tx.logs || []).filter((log) => logIds.has(log.logId))
142
+ for (const log of logs) {
143
+ const ctx = new FuelContext(
144
+ this.config.chainId,
145
+ this.config.address,
146
+ this.config.name ?? this.config.address,
147
+ tx
148
+ )
149
+ ctx.setLogIndex(log.receiptIndex)
150
+ await handler(log, ctx)
151
+ results.push(ctx.stopAndGetResult())
152
+ }
153
+ return mergeProcessResults(results)
154
+ },
155
+ logConfig: {
156
+ logIds: Array.from(logIds)
157
+ }
158
+ }
159
+ this.callHandlers.push(callHandler)
160
+ return this
161
+ }
125
162
  }
126
163
 
127
164
  export type FuelProcessorConfig = {
@@ -0,0 +1,48 @@
1
+ import { CallHandler, FuelBaseProcessor, FuelProcessorState } from './types.js'
2
+ import { Data_FuelCall } from '@sentio/protos'
3
+ import { Provider } from 'fuels'
4
+ import { getRpcEndpoint } from './network.js'
5
+ import { decodeFuelTransaction, DEFAULT_FUEL_FETCH_CONFIG, FuelFetchConfig, FuelTransaction } from './transaction.js'
6
+ import { FuelContext } from './context.js'
7
+ import { FuelProcessorConfig } from './fuel-processor.js'
8
+
9
+ type GlobalFuelProcessorConfig = Omit<FuelProcessorConfig, 'address' | 'abi'>
10
+
11
+ export class FuelGlobalProcessor implements FuelBaseProcessor<GlobalFuelProcessorConfig> {
12
+ callHandlers: CallHandler<Data_FuelCall>[] = []
13
+
14
+ private provider: Provider
15
+
16
+ static bind(config: GlobalFuelProcessorConfig): FuelGlobalProcessor {
17
+ const processor = new FuelGlobalProcessor(config)
18
+ FuelProcessorState.INSTANCE.addValue(processor)
19
+ return processor
20
+ }
21
+
22
+ constructor(readonly config: GlobalFuelProcessorConfig) {}
23
+
24
+ async configure() {
25
+ const url = getRpcEndpoint(this.config.chainId)
26
+ this.provider = await Provider.create(url)
27
+ }
28
+
29
+ public onTransaction(
30
+ handler: (transaction: FuelTransaction, ctx: FuelContext) => void | Promise<void>,
31
+ config: FuelFetchConfig = DEFAULT_FUEL_FETCH_CONFIG
32
+ ) {
33
+ const callHandler = {
34
+ handler: async (call: Data_FuelCall) => {
35
+ const tx = decodeFuelTransaction(call.transaction, this.provider)
36
+ const ctx = new FuelContext(this.config.chainId, '*', this.config.name ?? '*', tx)
37
+ await handler(tx, ctx)
38
+ return ctx.stopAndGetResult()
39
+ },
40
+ fetchConfig: {
41
+ filters: [],
42
+ ...config
43
+ }
44
+ }
45
+ this.callHandlers.push(callHandler)
46
+ return this
47
+ }
48
+ }
package/src/fuel/index.ts CHANGED
@@ -6,3 +6,4 @@ export * from './transaction.js'
6
6
  export * from './base-processor.js'
7
7
  export * from './asset-processor.js'
8
8
  export * from './types.js'
9
+ export * from './global-processor.js'
@@ -1,5 +1,5 @@
1
1
  import { FuelChainId } from '@sentio/chain'
2
- import { FUEL_BETA_5_NETWORK_URL, FUEL_NETWORK_URL } from '@fuel-ts/account/configs'
2
+ import { FUEL_BETA_5_NETWORK_URL, FUEL_NETWORK_URL } from 'fuels'
3
3
 
4
4
  export type FuelNetwork = FuelChainId
5
5
  export const FuelNetwork = <const>{
@@ -1,7 +1,20 @@
1
- import { AbiMap, assembleTransactionSummary, processGqlReceipt, Provider, TransactionSummary } from '@fuel-ts/account'
2
- import { TransactionCoder } from '@fuel-ts/transactions'
3
- import { bn } from '@fuel-ts/math'
4
- import { arrayify } from '@fuel-ts/utils'
1
+ import {
2
+ AbiMap,
3
+ arrayify,
4
+ assembleTransactionSummary,
5
+ BaseAssetId,
6
+ BigNumberCoder,
7
+ bn,
8
+ Input,
9
+ InputType,
10
+ Interface,
11
+ processGqlReceipt,
12
+ Provider,
13
+ ReceiptType,
14
+ TransactionCoder,
15
+ TransactionSummary
16
+ } from 'fuels'
17
+ import { FuelLog } from './types.js'
5
18
 
6
19
  export type FuelFetchConfig = {
7
20
  includeFailed?: boolean
@@ -13,6 +26,17 @@ export const DEFAULT_FUEL_FETCH_CONFIG: FuelFetchConfig = {
13
26
 
14
27
  export type FuelTransaction = TransactionSummary & {
15
28
  blockNumber?: string
29
+ logs?: FuelLog<any>[]
30
+ sender?: string
31
+ }
32
+
33
+ function findSenderFromInputs(inputs: Input[] | undefined): string | undefined {
34
+ for (const input of inputs || []) {
35
+ if (input.type == InputType.Coin && input.assetId == BaseAssetId) {
36
+ return input.owner
37
+ }
38
+ }
39
+ return undefined
16
40
  }
17
41
 
18
42
  export function decodeFuelTransaction(gqlTransaction: any, provider: Provider): FuelTransaction {
@@ -37,7 +61,8 @@ export function decodeFuelTransaction(gqlTransaction: any, provider: Provider):
37
61
  maxInputs,
38
62
  gasCosts
39
63
  }),
40
- blockNumber
64
+ blockNumber,
65
+ sender: findSenderFromInputs(decodedTransaction.inputs)
41
66
  }
42
67
  }
43
68
 
@@ -56,6 +81,21 @@ export function decodeFuelTransactionWithAbi(gqlTransaction: any, abiMap: AbiMap
56
81
  }
57
82
  const blockNumber = gqlTransactionStatus?.block?.header?.height
58
83
 
84
+ const abi = Object.values(abiMap)[0]
85
+
86
+ const logs = [] as FuelLog<any>[]
87
+ ;(receipts as any[]).forEach((receipt, idx) => {
88
+ if (receipt.type === ReceiptType.LogData || receipt.type === ReceiptType.Log) {
89
+ const interfaceToUse = new Interface(abi)
90
+
91
+ const data = receipt.type === ReceiptType.Log ? new BigNumberCoder('u64').encode(receipt.val0) : receipt.data
92
+
93
+ const logId = receipt.val1.toNumber()
94
+ const [decodedLog] = interfaceToUse.decodeLog(data, logId)
95
+ logs.push({ logId, data: decodedLog, receiptIndex: idx })
96
+ }
97
+ })
98
+
59
99
  return {
60
100
  ...assembleTransactionSummary({
61
101
  id: gqlTransaction.id,
@@ -69,6 +109,8 @@ export function decodeFuelTransactionWithAbi(gqlTransaction: any, abiMap: AbiMap
69
109
  maxInputs,
70
110
  gasCosts
71
111
  }),
72
- blockNumber
112
+ blockNumber,
113
+ logs,
114
+ sender: findSenderFromInputs(decodedTransaction.inputs)
73
115
  }
74
116
  }
package/src/fuel/types.ts CHANGED
@@ -15,4 +15,13 @@ export type CallHandler<T> = {
15
15
  handler: (call: T) => Promise<ProcessResult>
16
16
  fetchConfig?: Partial<FuelCallHandlerConfig>
17
17
  assetConfig?: Partial<FuelAssetHandlerConfig>
18
+ logConfig?: {
19
+ logIds: number[]
20
+ }
21
+ }
22
+
23
+ export interface FuelLog<T> {
24
+ logId: number
25
+ data: T
26
+ receiptIndex: number
18
27
  }
@@ -2,7 +2,7 @@
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
4
 
5
- /* Generated modules for account 0x1 */
5
+ /* Generated types for 0x1, original address 0x1 */
6
6
 
7
7
  import { TypeDescriptor, ANY_TYPE } from "@typemove/move";
8
8
  import { MoveCoder, TypedEventInstance } from "@typemove/sui";
@@ -2,7 +2,7 @@
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
4
 
5
- /* Generated modules for account 0x2 */
5
+ /* Generated types for 0x2, original address 0x2 */
6
6
 
7
7
  import { TypeDescriptor, ANY_TYPE } from "@typemove/move";
8
8
  import { MoveCoder, TypedEventInstance } from "@typemove/sui";
@@ -2,7 +2,7 @@
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
4
 
5
- /* Generated modules for account 0x3 */
5
+ /* Generated types for 0x3, original address 0x3 */
6
6
 
7
7
  import { TypeDescriptor, ANY_TYPE } from "@typemove/move";
8
8
  import { MoveCoder, TypedEventInstance } from "@typemove/sui";
@@ -51,6 +51,27 @@ export class FuelFacet {
51
51
  res.push(binding)
52
52
  }
53
53
  }
54
+
55
+ for (const logConfig of config.fuelLogConfigs) {
56
+ const binding = {
57
+ data: {
58
+ fuelCall: {
59
+ transaction,
60
+ timestamp: new Date()
61
+ }
62
+ },
63
+ handlerIds: [logConfig.handlerId],
64
+ handlerType: HandlerType.FUEL_CALL
65
+ }
66
+
67
+ const logIds = logConfig.logIds
68
+ for (const receipt of transaction.receipts || []) {
69
+ if ((receipt.receiptType == 'LOG' || receipt.receiptType == 'LOG_DATA') && logIds.includes(receipt.rb)) {
70
+ res.push(binding)
71
+ }
72
+ }
73
+ }
74
+
54
75
  for (const assetConfig of config.assetConfigs) {
55
76
  const binding = {
56
77
  data: {