@sentio/sdk 2.40.0-rc.2 → 2.40.0-rc.20

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 (135) hide show
  1. package/lib/aptos/aptos-processor.d.ts +1 -1
  2. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  3. package/lib/aptos/aptos-processor.js +1 -1
  4. package/lib/aptos/aptos-processor.js.map +1 -1
  5. package/lib/aptos/context.d.ts +2 -2
  6. package/lib/aptos/context.d.ts.map +1 -1
  7. package/lib/aptos/context.js +1 -1
  8. package/lib/aptos/ext/aptos-dex.d.ts +1 -1
  9. package/lib/aptos/ext/aptos-dex.d.ts.map +1 -1
  10. package/lib/aptos/ext/aptos-dex.js +1 -1
  11. package/lib/aptos/ext/aptos-dex.js.map +1 -1
  12. package/lib/aptos/ext/coin-event.d.ts +1 -1
  13. package/lib/aptos/ext/coin-event.d.ts.map +1 -1
  14. package/lib/aptos/ext/coin.js +2 -2
  15. package/lib/aptos/ext/coin.js.map +1 -1
  16. package/lib/eth/account-processor.d.ts +21 -7
  17. package/lib/eth/account-processor.d.ts.map +1 -1
  18. package/lib/eth/account-processor.js +2 -2
  19. package/lib/eth/account-processor.js.map +1 -1
  20. package/lib/eth/base-processor-template.d.ts +24 -8
  21. package/lib/eth/base-processor-template.d.ts.map +1 -1
  22. package/lib/eth/base-processor-template.js.map +1 -1
  23. package/lib/eth/base-processor.d.ts +30 -10
  24. package/lib/eth/base-processor.d.ts.map +1 -1
  25. package/lib/eth/base-processor.js +6 -6
  26. package/lib/eth/base-processor.js.map +1 -1
  27. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +100 -31
  28. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
  29. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +1295 -46
  30. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  31. package/lib/eth/builtin/internal/erc1155-processor.d.ts +55 -16
  32. package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
  33. package/lib/eth/builtin/internal/erc1155-processor.js +510 -16
  34. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  35. package/lib/eth/builtin/internal/erc20-processor.d.ts +79 -24
  36. package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
  37. package/lib/eth/builtin/internal/erc20-processor.js +1039 -36
  38. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  39. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +46 -13
  40. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
  41. package/lib/eth/builtin/internal/erc20bytes-processor.js +512 -18
  42. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  43. package/lib/eth/builtin/internal/erc721-processor.d.ts +67 -20
  44. package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
  45. package/lib/eth/builtin/internal/erc721-processor.js +826 -28
  46. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  47. package/lib/eth/builtin/internal/weth9-processor.d.ts +64 -19
  48. package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
  49. package/lib/eth/builtin/internal/weth9-processor.js +607 -22
  50. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  51. package/lib/eth/codegen/event-handler.js +1 -1
  52. package/lib/eth/codegen/file.d.ts.map +1 -1
  53. package/lib/eth/codegen/file.js +21 -3
  54. package/lib/eth/codegen/file.js.map +1 -1
  55. package/lib/eth/codegen/function-calls.d.ts +4 -0
  56. package/lib/eth/codegen/function-calls.d.ts.map +1 -1
  57. package/lib/eth/codegen/function-calls.js +83 -5
  58. package/lib/eth/codegen/function-calls.js.map +1 -1
  59. package/lib/eth/codegen/types.d.ts +1 -0
  60. package/lib/eth/codegen/types.d.ts.map +1 -1
  61. package/lib/eth/codegen/types.js +13 -0
  62. package/lib/eth/codegen/types.js.map +1 -1
  63. package/lib/eth/context.d.ts +4 -0
  64. package/lib/eth/context.d.ts.map +1 -1
  65. package/lib/eth/context.js +4 -0
  66. package/lib/eth/context.js.map +1 -1
  67. package/lib/eth/eth-plugin.d.ts +27 -9
  68. package/lib/eth/eth-plugin.d.ts.map +1 -1
  69. package/lib/eth/eth-plugin.js +17 -17
  70. package/lib/eth/eth-plugin.js.map +1 -1
  71. package/lib/eth/generic-processor.test.js.map +1 -1
  72. package/lib/eth/index.d.ts +1 -0
  73. package/lib/eth/index.d.ts.map +1 -1
  74. package/lib/eth/index.js +1 -0
  75. package/lib/eth/index.js.map +1 -1
  76. package/lib/solana/builtin/spl-token-processor.d.ts +1 -1
  77. package/lib/solana/builtin/spl-token-processor.d.ts.map +1 -1
  78. package/lib/solana/builtin/spl-token-processor.js +1 -1
  79. package/lib/solana/builtin/spl-token-processor.js.map +1 -1
  80. package/lib/solana/solana-context.d.ts +1 -1
  81. package/lib/solana/solana-context.js +2 -2
  82. package/lib/store/cache.d.ts +14 -0
  83. package/lib/store/cache.d.ts.map +1 -0
  84. package/lib/store/cache.js +35 -0
  85. package/lib/store/cache.js.map +1 -0
  86. package/lib/store/store.d.ts +2 -3
  87. package/lib/store/store.d.ts.map +1 -1
  88. package/lib/store/store.js +34 -8
  89. package/lib/store/store.js.map +1 -1
  90. package/lib/sui/context.d.ts +1 -1
  91. package/lib/sui/context.d.ts.map +1 -1
  92. package/lib/sui/sui-processor.d.ts +1 -1
  93. package/lib/sui/sui-processor.d.ts.map +1 -1
  94. package/lib/sui/sui-processor.js +1 -1
  95. package/lib/sui/sui-processor.js.map +1 -1
  96. package/lib/testing/aptos-facet.d.ts +1 -1
  97. package/lib/testing/aptos-facet.js +2 -2
  98. package/lib/testing/sui-facet.js +1 -1
  99. package/lib/utils/dex-price.d.ts +1 -0
  100. package/lib/utils/dex-price.d.ts.map +1 -1
  101. package/lib/utils/dex-price.js +13 -2
  102. package/lib/utils/dex-price.js.map +1 -1
  103. package/package.json +8 -7
  104. package/src/aptos/aptos-processor.ts +1 -1
  105. package/src/aptos/context.ts +2 -2
  106. package/src/aptos/ext/aptos-dex.ts +1 -1
  107. package/src/aptos/ext/coin-event.ts +1 -1
  108. package/src/aptos/ext/coin.ts +2 -2
  109. package/src/eth/account-processor.ts +28 -12
  110. package/src/eth/base-processor-template.ts +16 -8
  111. package/src/eth/base-processor.ts +25 -16
  112. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +1643 -123
  113. package/src/eth/builtin/internal/erc1155-processor.ts +724 -42
  114. package/src/eth/builtin/internal/erc20-processor.ts +1368 -90
  115. package/src/eth/builtin/internal/erc20bytes-processor.ts +685 -49
  116. package/src/eth/builtin/internal/erc721-processor.ts +1116 -70
  117. package/src/eth/builtin/internal/weth9-processor.ts +798 -63
  118. package/src/eth/codegen/event-handler.ts +1 -1
  119. package/src/eth/codegen/file.ts +26 -3
  120. package/src/eth/codegen/function-calls.ts +101 -8
  121. package/src/eth/codegen/types.ts +22 -1
  122. package/src/eth/context.ts +7 -0
  123. package/src/eth/eth-plugin.ts +31 -26
  124. package/src/eth/index.ts +2 -0
  125. package/src/solana/builtin/spl-token-processor.ts +1 -1
  126. package/src/solana/solana-context.ts +2 -2
  127. package/src/store/cache.ts +46 -0
  128. package/src/store/store.ts +62 -34
  129. package/src/sui/context.ts +1 -1
  130. package/src/sui/sui-processor.ts +1 -1
  131. package/src/testing/aptos-facet.ts +2 -2
  132. package/src/testing/sui-facet.ts +1 -1
  133. package/src/utils/dex-price.ts +15 -2
  134. package/lib/utils/chainlink-oracles-sepolia.csv +0 -19
  135. package/lib/utils/chainlink-oracles.csv +0 -217
@@ -12,7 +12,7 @@ export function generateEventHandler(event: EventDeclaration, contractName: stri
12
12
  handler: (event: ${eventNamePrefix}Event, ctx: ${contractName}Context) => void,
13
13
  filter?: ${eventNamePrefix}EventFilter | ${eventNamePrefix}EventFilter[],
14
14
  fetchConfig?: Partial<EthFetchConfig>,
15
- preprocessHandler?: (event: ${eventNamePrefix}Event, ctx: ${contractName}Context) => Promise<PreprocessResult>
15
+ preprocessHandler?: (event: ${eventNamePrefix}Event, ctx: ${contractName}Context, preprocessStore: {[k: string]: any}) => Promise<PreprocessResult>
16
16
  ): this {
17
17
  if (!filter) {
18
18
  filter = templateContract.filters['${filterName}'](${event.inputs.map(() => 'null').join(',')})
@@ -9,7 +9,12 @@ import {
9
9
  import { reservedKeywords } from '@sentio/ethers-v6/dist/codegen/reserved-keywords.js'
10
10
  import { codegenCallTraceTypes, generateCallHandlers } from './functions-handler.js'
11
11
  import { generateEventFilters, generateEventHandlers } from './event-handler.js'
12
- import { generateBoundViewFunctions, generateViewFunctions } from './function-calls.js'
12
+ import {
13
+ generateBoundFunctionCallEncoders,
14
+ generateBoundViewFunctions,
15
+ generateFunctionCallEncoders,
16
+ generateViewFunctions
17
+ } from './function-calls.js'
13
18
 
14
19
  export function codeGenIndex(contract: Contract): string {
15
20
  return `
@@ -44,6 +49,13 @@ export function codeGenSentioFile(contract: Contract): string {
44
49
  .flatMap((fs) => generateViewFunctions(false, fs))
45
50
  .join(',\n')}
46
51
  }
52
+
53
+ encodeCall = {
54
+ ${Object.values(contract.functions)
55
+ .filter((f) => !reservedKeywords.has(f[0].name))
56
+ .flatMap((fs) => generateFunctionCallEncoders(fs))
57
+ .join(',\n')}
58
+ }
47
59
  }
48
60
 
49
61
  export class ${contract.name}BoundContractView extends BoundContractView<${contract.name},
@@ -61,6 +73,15 @@ export function codeGenSentioFile(contract: Contract): string {
61
73
  .flatMap((fs) => generateBoundViewFunctions(false, fs))
62
74
  .join(',\n')}
63
75
  }
76
+
77
+ encodeCall = {
78
+ view: this.view,
79
+ context: this.context,
80
+ ${Object.values(contract.functions)
81
+ .filter((f) => !reservedKeywords.has(f[0].name))
82
+ .flatMap((fs) => generateBoundFunctionCallEncoders(fs))
83
+ .join(',\n')}
84
+ }
64
85
  }
65
86
 
66
87
  export type ${contract.name}Context = ContractContext<${contract.name}, ${contract.name}BoundContractView>
@@ -173,7 +194,7 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
173
194
 
174
195
  const imports = createImportsForUsedIdentifiers(
175
196
  {
176
- ethers: ['BigNumberish', 'Overrides', 'BytesLike'],
197
+ ethers: ['BigNumberish', 'Overrides', 'BytesLike', 'Interface'],
177
198
  // 'ethers/providers': ['Networkish'],
178
199
  '@sentio/sdk/eth': [
179
200
  'addContractByABI',
@@ -195,10 +216,12 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
195
216
  'TypedCallTrace',
196
217
  'EthContext',
197
218
  'EthFetchConfig',
198
- 'PreprocessResult'
219
+ 'PreprocessResult',
220
+ 'makeEthCallKey'
199
221
  ],
200
222
  // '@sentio/sdk/eth': ['BaseContext'],
201
223
  // '@sentio/protos': ['EthFetchConfig'],
224
+ '@sentio/protos': ['EthCallParam', 'EthCallContext', 'PreparedData'],
202
225
  './common.js': ['PromiseOrValue'],
203
226
  './index.js': [`${contract.name}__factory`],
204
227
  [`./${contract.name}.js`]: [`${contract.name}`, ...eventsImports, ...uniqueStructImports]
@@ -1,7 +1,11 @@
1
1
  // https://github.com/dethcrypto/TypeChain/blob/015abb28bd22826611051f27e0ec96a00f9a0b61/packages/target-ethers-v5/src/codegen/functions.ts#L54
2
- import { FunctionDeclaration } from 'typechain'
2
+ import { FunctionDeclaration, getSignatureForFn } from 'typechain'
3
3
  import { generateInputTypes, generateOutputTypes } from '@sentio/ethers-v6/dist/codegen/types.js'
4
- import { getFullSignatureAsSymbolForFunction, getFullSignatureForFunction } from './types.js'
4
+ import {
5
+ getFullSignatureAsSymbolForFunction,
6
+ getFullSignatureForFunction,
7
+ getFullSignatureWithOutputForFn
8
+ } from './types.js'
5
9
 
6
10
  function generateReturnTypes(fn: FunctionDeclaration) {
7
11
  // sounds like returnResultObject should be true but we need to set false to make it work
@@ -34,11 +38,33 @@ export function generateViewFunction(view: boolean, fn: FunctionDeclaration, inc
34
38
  `
35
39
  async ${declName}(${generateInputTypes(fn.inputs, {
36
40
  useStructs: true
37
- })}overrides?: Overrides): ${generateReturnTypes(fn)} {
38
- try {
39
- return await ${func}${call}(${
40
- fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
41
- } overrides || {})
41
+ })}overrides?: Overrides, preparedData?: PreparedData, ethCallContext?: EthCallContext): ${generateReturnTypes(fn)} {
42
+ try {
43
+ if (preparedData?.ethCallResults && ethCallContext) {
44
+ const iface = new Interface(["function ${getFullSignatureWithOutputForFn(fn)}"])
45
+ const calldata = iface.encodeFunctionData(
46
+ "${fn.name}",[${
47
+ fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
48
+ }]
49
+ )
50
+ const key = makeEthCallKey({
51
+ context: ethCallContext,
52
+ calldata
53
+ })
54
+ console.debug("looking up eth call key:", key)
55
+ const ret = preparedData.ethCallResults[key]
56
+ if (ret) {
57
+ console.debug("prepared eth call found:", key)
58
+ const result = iface.decodeFunctionResult("${fn.name}", ret).toArray()
59
+ return result.length == 1? result[0]: result
60
+ }
61
+ console.debug("missing eth call key:", "${fn.name}", ${
62
+ fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
63
+ }key)
64
+ }
65
+ return await ${func}${call}(${
66
+ fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
67
+ } overrides || {})
42
68
  } catch (e) {
43
69
  const stack = new Error().stack
44
70
  throw transformEtherError(e, undefined, stack)
@@ -67,12 +93,79 @@ export function generateBoundViewFunction(view: boolean, fn: FunctionDeclaration
67
93
  async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
68
94
  useStructs: true
69
95
  })}overrides?: Overrides): ${generateReturnTypes(fn)} {
96
+ const ethCallContext = {
97
+ chainId: this.context.chainId,
98
+ blockTag: "0x" + this.context.blockNumber.toString(16),
99
+ address: this.context.address,
100
+ }
70
101
  return await this.${qualifier}.${declName}(${
71
102
  fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
72
103
  } {
73
104
  blockTag: this.context.blockNumber,
74
105
  ...overrides
75
- })
106
+ }, this.context.preparedData, ethCallContext)
107
+ }
108
+ `
109
+ ]
110
+ }
111
+
112
+ // TODO add tests for these
113
+ export function generateFunctionCallEncoders(functions: FunctionDeclaration[]): string[] {
114
+ const includeArgTypes = functions.length !== 1
115
+ return functions.flatMap((fn) => generateFunctionCallEncoder(fn, includeArgTypes))
116
+ }
117
+
118
+ export function generateFunctionCallEncoder(fn: FunctionDeclaration, includeArgTypes: boolean): string[] {
119
+ const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name
120
+ return [
121
+ `
122
+ ${declName}(${generateInputTypes(fn.inputs, {
123
+ useStructs: true
124
+ })}ethCallContext: EthCallContext): EthCallParam {
125
+ try {
126
+ const iface = new Interface(["function ${getSignatureForFn(fn)}"])
127
+ const calldata = iface.encodeFunctionData(
128
+ "${fn.name}",[${
129
+ fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
130
+ }]
131
+ )
132
+ return {
133
+ context: ethCallContext,
134
+ calldata
135
+ }
136
+ } catch (e) {
137
+ const stack = new Error().stack
138
+ throw transformEtherError(e, undefined, stack)
139
+ }
140
+ }
141
+ `
142
+ ]
143
+ }
144
+
145
+ export function generateBoundFunctionCallEncoders(functions: FunctionDeclaration[]): string[] {
146
+ const includeArgTypes = functions.length !== 1
147
+ return functions.flatMap((fn) => generateBoundFunctionCallEncoder(fn, includeArgTypes))
148
+ }
149
+
150
+ export function generateBoundFunctionCallEncoder(fn: FunctionDeclaration, includeArgTypes: boolean): string[] {
151
+ const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name
152
+
153
+ // TODO need override address?
154
+ return [
155
+ `
156
+ ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
157
+ useStructs: true
158
+ })}overrides?: Overrides): EthCallParam {
159
+ const chainId = overrides?.chainId?.toString() ?? this.context.chainId.toString()
160
+ const address = this.context.address
161
+ let blockTag = "0x" + this.context.blockNumber.toString(16)
162
+ if (overrides?.blockTag) {
163
+ blockTag = typeof(overrides.blockTag) == 'string'? overrides.blockTag: "0x" + overrides.blockTag.toString(16)
164
+ }
165
+
166
+ return this.view.encodeCall.${declName}(${
167
+ fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
168
+ }{chainId, address, blockTag})
76
169
  }
77
170
  `
78
171
  ]
@@ -1,4 +1,11 @@
1
- import { EventDeclaration, FunctionDeclaration } from 'typechain'
1
+ import {
2
+ AbiOutputParameter,
3
+ AbiParameter,
4
+ EventDeclaration,
5
+ FunctionDeclaration,
6
+ getArgumentForSignature,
7
+ getSignatureForFn
8
+ } from 'typechain'
2
9
  import { EvmType } from 'typechain/dist/parser/parseEvmType.js'
3
10
 
4
11
  export function getFullSignatureAsSymbolForFunction(fn: FunctionDeclaration): string {
@@ -40,3 +47,17 @@ export function getFullSignatureForFunction(fn: FunctionDeclaration): string {
40
47
  })
41
48
  .join(',')})`
42
49
  }
50
+
51
+ function getOutputArgumentForSignature(argument: AbiOutputParameter) {
52
+ if (argument.type.type == 'void') {
53
+ return ''
54
+ }
55
+ return getArgumentForSignature(argument as AbiParameter)
56
+ }
57
+
58
+ export function getFullSignatureWithOutputForFn(fn: FunctionDeclaration) {
59
+ return `${getSignatureForFn(fn)} ${fn.stateMutability} returns (${fn.outputs
60
+ .map((i) => getOutputArgumentForSignature(i))
61
+ .filter((s) => s != '')
62
+ .join(',')})`
63
+ }
@@ -188,6 +188,9 @@ export class ContractContext<
188
188
  if (view.callStatic) {
189
189
  view.callStatic.context = this
190
190
  }
191
+ if (view.encodeCall) {
192
+ view.encodeCall.context = this
193
+ }
191
194
  this.contractName = contractName
192
195
  this.contract = view
193
196
  }
@@ -226,6 +229,10 @@ export class BoundContractView<TContract extends BaseContract, TContractView ext
226
229
  context: EthContext
227
230
  view: TContractView
228
231
  }
232
+ encodeCall: {
233
+ context: EthContext
234
+ view: TContractView
235
+ }
229
236
 
230
237
  constructor(address: string, view: TContractView) {
231
238
  this.address = address
@@ -35,10 +35,13 @@ interface Handlers {
35
35
  }
36
36
 
37
37
  interface PreprocessHandlers {
38
- eventHandlers: ((event: Data_EthLog) => Promise<PreprocessResult>)[]
39
- traceHandlers: ((trace: Data_EthTrace) => Promise<PreprocessResult>)[]
40
- blockHandlers: ((block: Data_EthBlock) => Promise<PreprocessResult>)[]
41
- transactionHandlers: ((txn: Data_EthTransaction) => Promise<PreprocessResult>)[]
38
+ eventHandlers: ((event: Data_EthLog, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>)[]
39
+ traceHandlers: ((trace: Data_EthTrace, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>)[]
40
+ blockHandlers: ((block: Data_EthBlock, preprocessStore: { [k: string]: any }) => Promise<PreprocessResult>)[]
41
+ transactionHandlers: ((
42
+ txn: Data_EthTransaction,
43
+ preprocessStore: { [k: string]: any }
44
+ ) => Promise<PreprocessResult>)[]
42
45
  }
43
46
 
44
47
  export class EthPlugin extends Plugin {
@@ -278,16 +281,16 @@ export class EthPlugin extends Plugin {
278
281
  }
279
282
  }
280
283
 
281
- preprocessBinding(request: DataBinding): Promise<PreprocessResult> {
284
+ preprocessBinding(request: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
282
285
  switch (request.handlerType) {
283
286
  case HandlerType.ETH_LOG:
284
- return this.preprocessLog(request)
287
+ return this.preprocessLog(request, preprocessStore)
285
288
  case HandlerType.ETH_TRACE:
286
- return this.preprocessTrace(request)
289
+ return this.preprocessTrace(request, preprocessStore)
287
290
  case HandlerType.ETH_BLOCK:
288
- return this.preprocessBlock(request)
291
+ return this.preprocessBlock(request, preprocessStore)
289
292
  case HandlerType.ETH_TRANSACTION:
290
- return this.preprocessTransaction(request)
293
+ return this.preprocessTransaction(request, preprocessStore)
291
294
  default:
292
295
  throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
293
296
  }
@@ -326,7 +329,7 @@ export class EthPlugin extends Plugin {
326
329
  return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length
327
330
  }
328
331
 
329
- async preprocessLog(request: DataBinding): Promise<PreprocessResult> {
332
+ async preprocessLog(request: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
330
333
  if (!request.data?.ethLog?.log) {
331
334
  throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
332
335
  }
@@ -335,7 +338,7 @@ export class EthPlugin extends Plugin {
335
338
  const promises: Promise<PreprocessResult>[] = []
336
339
  for (const handlerId of request.handlerIds) {
337
340
  const handler = this.preprocessHandlers.eventHandlers[handlerId]
338
- const promise = handler(ethLog).catch((e) => {
341
+ const promise = handler(ethLog, preprocessStore).catch((e) => {
339
342
  throw new ServerError(
340
343
  Status.INTERNAL,
341
344
  'error processing log: ' + JSON.stringify(ethLog.log) + '\n' + errorString(e)
@@ -346,7 +349,7 @@ export class EthPlugin extends Plugin {
346
349
  return mergePreprocessResults(await Promise.all(promises))
347
350
  }
348
351
 
349
- async preprocessTrace(binding: DataBinding): Promise<PreprocessResult> {
352
+ async preprocessTrace(binding: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
350
353
  if (!binding.data?.ethTrace?.trace) {
351
354
  throw new ServerError(Status.INVALID_ARGUMENT, "Trace can't be null")
352
355
  }
@@ -355,7 +358,7 @@ export class EthPlugin extends Plugin {
355
358
  const promises: Promise<PreprocessResult>[] = []
356
359
 
357
360
  for (const handlerId of binding.handlerIds) {
358
- const promise = this.preprocessHandlers.traceHandlers[handlerId](ethTrace).catch((e) => {
361
+ const promise = this.preprocessHandlers.traceHandlers[handlerId](ethTrace, preprocessStore).catch((e) => {
359
362
  throw new ServerError(
360
363
  Status.INTERNAL,
361
364
  'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e)
@@ -366,7 +369,7 @@ export class EthPlugin extends Plugin {
366
369
  return mergePreprocessResults(await Promise.all(promises))
367
370
  }
368
371
 
369
- async preprocessBlock(binding: DataBinding): Promise<PreprocessResult> {
372
+ async preprocessBlock(binding: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
370
373
  if (!binding.data?.ethBlock?.block) {
371
374
  throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
372
375
  }
@@ -374,7 +377,7 @@ export class EthPlugin extends Plugin {
374
377
 
375
378
  const promises: Promise<PreprocessResult>[] = []
376
379
  for (const handlerId of binding.handlerIds) {
377
- const promise = this.preprocessHandlers.blockHandlers[handlerId](ethBlock).catch((e) => {
380
+ const promise = this.preprocessHandlers.blockHandlers[handlerId](ethBlock, preprocessStore).catch((e) => {
378
381
  throw new ServerError(
379
382
  Status.INTERNAL,
380
383
  'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e)
@@ -385,7 +388,7 @@ export class EthPlugin extends Plugin {
385
388
  return mergePreprocessResults(await Promise.all(promises))
386
389
  }
387
390
 
388
- async preprocessTransaction(binding: DataBinding): Promise<PreprocessResult> {
391
+ async preprocessTransaction(binding: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
389
392
  if (!binding.data?.ethTransaction?.transaction) {
390
393
  throw new ServerError(Status.INVALID_ARGUMENT, "transaction can't be null")
391
394
  }
@@ -394,12 +397,14 @@ export class EthPlugin extends Plugin {
394
397
  const promises: Promise<PreprocessResult>[] = []
395
398
 
396
399
  for (const handlerId of binding.handlerIds) {
397
- const promise = this.preprocessHandlers.transactionHandlers[handlerId](ethTransaction).catch((e) => {
398
- throw new ServerError(
399
- Status.INTERNAL,
400
- 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e)
401
- )
402
- })
400
+ const promise = this.preprocessHandlers.transactionHandlers[handlerId](ethTransaction, preprocessStore).catch(
401
+ (e) => {
402
+ throw new ServerError(
403
+ Status.INTERNAL,
404
+ 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e)
405
+ )
406
+ }
407
+ )
403
408
  promises.push(promise)
404
409
  }
405
410
  return mergePreprocessResults(await Promise.all(promises))
@@ -414,7 +419,7 @@ export class EthPlugin extends Plugin {
414
419
  const promises: Promise<ProcessResult>[] = []
415
420
  for (const handlerId of request.handlerIds) {
416
421
  const handler = this.handlers.eventHandlers[handlerId]
417
- const promise = handler(ethLog).catch((e) => {
422
+ const promise = handler(ethLog, preparedData).catch((e) => {
418
423
  throw new ServerError(
419
424
  Status.INTERNAL,
420
425
  'error processing log: ' + JSON.stringify(ethLog.log) + '\n' + errorString(e)
@@ -437,7 +442,7 @@ export class EthPlugin extends Plugin {
437
442
  const promises: Promise<ProcessResult>[] = []
438
443
 
439
444
  for (const handlerId of binding.handlerIds) {
440
- const promise = this.handlers.traceHandlers[handlerId](ethTrace).catch((e) => {
445
+ const promise = this.handlers.traceHandlers[handlerId](ethTrace, preparedData).catch((e) => {
441
446
  throw new ServerError(
442
447
  Status.INTERNAL,
443
448
  'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e)
@@ -459,7 +464,7 @@ export class EthPlugin extends Plugin {
459
464
 
460
465
  const promises: Promise<ProcessResult>[] = []
461
466
  for (const handlerId of binding.handlerIds) {
462
- const promise = this.handlers.blockHandlers[handlerId](ethBlock).catch((e) => {
467
+ const promise = this.handlers.blockHandlers[handlerId](ethBlock, preparedData).catch((e) => {
463
468
  throw new ServerError(
464
469
  Status.INTERNAL,
465
470
  'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e)
@@ -482,7 +487,7 @@ export class EthPlugin extends Plugin {
482
487
  const promises: Promise<ProcessResult>[] = []
483
488
 
484
489
  for (const handlerId of binding.handlerIds) {
485
- const promise = this.handlers.transactionHandlers[handlerId](ethTransaction).catch((e) => {
490
+ const promise = this.handlers.transactionHandlers[handlerId](ethTransaction, preparedData).catch((e) => {
486
491
  throw new ServerError(
487
492
  Status.INTERNAL,
488
493
  'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e)
package/src/eth/index.ts CHANGED
@@ -14,3 +14,5 @@ export { EthPlugin } from './eth-plugin.js'
14
14
  export { EthFetchConfig, PreprocessResult } from '@sentio/protos'
15
15
 
16
16
  export { EthChainId } from '@sentio/chain'
17
+
18
+ export { makeEthCallKey } from '@sentio/runtime'
@@ -1,4 +1,4 @@
1
- import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from '@sentio/sdk/solana'
1
+ import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from "../index.js"
2
2
  import { Instruction } from '@project-serum/anchor'
3
3
  import { AmountToUiAmount, Approve, ApproveChecked, Burn, BurnChecked, CloseAccount, CreateNativeMint, DefaultAccountStateExtension, FreezeAccount, GetAccountDataSize, InitializeAccount, InitializeAccount2, InitializeAccount3, InitializeImmutableOwner, InitializeMint, InitializeMintCloseAuthority, InitializeMultisig, MemoTransferExtension, MintTo, MintToChecked, Reallocate, Revoke, SyncNative, ThawAccount, Transfer, TransferChecked, TransferFeeExtension, UiAmountToAmount } from './types.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { normalizeLabels, Labels, BaseContext, RecordMetaData } from '@sentio/sdk'
1
+ import { normalizeLabels, Labels, BaseContext, RecordMetaData } from '../index.js'
2
2
  import { SolanaChainId } from '@sentio/chain'
3
3
 
4
4
  export class SolanaContext extends BaseContext {
@@ -35,7 +35,7 @@ export class SolanaContext extends BaseContext {
35
35
  logIndex: 0,
36
36
  chainId: this.getChainId(),
37
37
  name: name,
38
- labels: normalizeLabels(labels),
38
+ labels: normalizeLabels(labels)
39
39
  }
40
40
  }
41
41
  }
@@ -0,0 +1,46 @@
1
+ import { ID } from './types.js'
2
+ import type { Entity as EntityStruct } from '@sentio/protos'
3
+
4
+ export interface Entity {
5
+ id: ID
6
+ }
7
+
8
+ export class LocalCache {
9
+ private cache: Map<string, EntityStruct> = new Map()
10
+
11
+ getKey(entity: string, id: ID) {
12
+ return `${entity}-${id}`
13
+ }
14
+
15
+ has(entity: string, id: ID): boolean {
16
+ return this.cache.has(this.getKey(entity, id))
17
+ }
18
+
19
+ get(entity: string, id: ID): EntityStruct | undefined {
20
+ return this.cache.get(this.getKey(entity, id))
21
+ }
22
+
23
+ set(entity: EntityStruct) {
24
+ const id = entity.data?.fields['id'].stringValue
25
+ if (id) {
26
+ const key = this.getKey(entity.entity, id)
27
+ let fields = entity.data?.fields || {}
28
+ if (this.cache.has(key)) {
29
+ const existFields = this.cache.get(key)?.data?.fields || {}
30
+ fields = Object.assign(existFields, fields)
31
+ }
32
+ this.cache.set(key, {
33
+ ...entity,
34
+ data: {
35
+ fields
36
+ }
37
+ })
38
+ }
39
+ }
40
+
41
+ delete(entityName: string, id: string | undefined) {
42
+ if (id) {
43
+ this.cache.delete(this.getKey(entityName, id))
44
+ }
45
+ }
46
+ }