@sentio/sdk 2.0.0-rc.13 → 2.0.0-rc.14

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 (46) hide show
  1. package/lib/builtin/internal/eacaggregatorproxy_processor.js +90 -180
  2. package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
  3. package/lib/builtin/internal/erc1155_processor.js +25 -50
  4. package/lib/builtin/internal/erc1155_processor.js.map +1 -1
  5. package/lib/builtin/internal/erc20_processor.js +40 -80
  6. package/lib/builtin/internal/erc20_processor.js.map +1 -1
  7. package/lib/builtin/internal/erc20bytes_processor.js +30 -60
  8. package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
  9. package/lib/builtin/internal/erc721_processor.js +45 -90
  10. package/lib/builtin/internal/erc721_processor.js.map +1 -1
  11. package/lib/builtin/internal/weth9_processor.js +30 -60
  12. package/lib/builtin/internal/weth9_processor.js.map +1 -1
  13. package/lib/error.d.ts +1 -1
  14. package/lib/error.js +10 -12
  15. package/lib/error.js.map +1 -1
  16. package/lib/eth/base-processor-template.d.ts +3 -3
  17. package/lib/eth/base-processor-template.js.map +1 -1
  18. package/lib/eth/base-processor.d.ts +3 -3
  19. package/lib/eth/base-processor.js.map +1 -1
  20. package/lib/eth/{eth-event.d.ts → eth.d.ts} +1 -1
  21. package/lib/eth/eth.js +2 -0
  22. package/lib/eth/eth.js.map +1 -0
  23. package/lib/eth/index.d.ts +1 -0
  24. package/lib/eth/index.js +1 -0
  25. package/lib/eth/index.js.map +1 -1
  26. package/lib/index.d.ts +1 -1
  27. package/lib/index.js +1 -1
  28. package/lib/index.js.map +1 -1
  29. package/lib/target-ethers-sentio/view-function.cjs +4 -9
  30. package/lib/target-ethers-sentio/view-function.cjs.map +1 -1
  31. package/package.json +5 -4
  32. package/src/builtin/internal/eacaggregatorproxy_processor.ts +90 -162
  33. package/src/builtin/internal/erc1155_processor.ts +25 -49
  34. package/src/builtin/internal/erc20_processor.ts +40 -72
  35. package/src/builtin/internal/erc20bytes_processor.ts +30 -54
  36. package/src/builtin/internal/erc721_processor.ts +45 -81
  37. package/src/builtin/internal/weth9_processor.ts +30 -54
  38. package/src/error.ts +12 -14
  39. package/src/eth/base-processor-template.ts +3 -3
  40. package/src/eth/base-processor.ts +4 -4
  41. package/src/eth/{eth-event.ts → eth.ts} +1 -1
  42. package/src/eth/index.ts +2 -0
  43. package/src/index.ts +1 -1
  44. package/src/target-ethers-sentio/view-function.cts +4 -11
  45. package/lib/eth/eth-event.js +0 -2
  46. package/lib/eth/eth-event.js.map +0 -1
package/src/error.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  // Transform error in more readable format
2
2
  import { ContractContext } from './core/context.js'
3
+ import { CallExceptionError } from 'ethers'
3
4
  // import { errors } from 'ethers/providers'
4
5
 
5
- export class EthersError extends Error {
6
+ export class SimpleEthersError extends Error {
6
7
  e: Error
7
8
 
8
9
  constructor(message: string, e: Error) {
@@ -16,11 +17,14 @@ export class EthersError extends Error {
16
17
  }
17
18
 
18
19
  export function transformEtherError(e: Error, ctx: ContractContext<any, any> | undefined): Error {
20
+ if (e instanceof SimpleEthersError) {
21
+ return e
22
+ }
23
+
19
24
  let msg = ''
20
- // @ts-ignore expected error fields
21
- if (e.code === errors.CALL_EXCEPTION) {
22
- // @ts-ignore expected error fields
23
- if (e.data === '0x') {
25
+ const err = e as CallExceptionError
26
+ if (err.code === 'CALL_EXCEPTION') {
27
+ if (err.data === '0x') {
24
28
  if (ctx) {
25
29
  msg =
26
30
  "jsonrpc eth_call return '0x' (likely contract not existed) at chain " +
@@ -28,18 +32,12 @@ export function transformEtherError(e: Error, ctx: ContractContext<any, any> | u
28
32
  ': ' +
29
33
  JSON.stringify(e)
30
34
  } else {
31
- msg = "jsonrpc eth_call return '0x' (likely contract not existed): " + JSON.stringify(e)
35
+ msg = "jsonrpc eth_call return '0x' (likely contract not existed): " + JSON.stringify(err)
32
36
  }
37
+ return new SimpleEthersError(msg, err)
33
38
  }
34
- return new EthersError(msg, e)
35
39
  }
36
40
 
37
- if (e instanceof EthersError) {
38
- return e
39
- }
40
-
41
- // TODO gracefully handle more errors
42
-
43
- msg = 'ethers call error\n' + e.message + '\n' + e.stack?.toString()
41
+ msg = 'ethers call error\n' + JSON.stringify(e) + '\n' + e.stack?.toString()
44
42
  return new Error(msg)
45
43
  }
@@ -8,7 +8,7 @@ import { Trace } from './trace.js'
8
8
  import { ListStateStorage } from '@sentio/runtime'
9
9
  import { EventFilter, LogParams, Network } from 'ethers/providers'
10
10
  import { DeferredTopicFilter } from 'ethers/contract'
11
- import { EthEvent } from './eth-event.js'
11
+ import { Eth } from './eth.js'
12
12
 
13
13
  export class ProcessorTemplateProcessorState extends ListStateStorage<
14
14
  BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>
@@ -37,7 +37,7 @@ export abstract class BaseProcessorTemplate<
37
37
  fetchConfig?: EthFetchConfig
38
38
  }[] = []
39
39
  eventHandlers: {
40
- handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
40
+ handler: (event: Eth, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
41
41
  filter: DeferredTopicFilter | DeferredTopicFilter[]
42
42
  fetchConfig?: EthFetchConfig
43
43
  }[] = []
@@ -88,7 +88,7 @@ export abstract class BaseProcessorTemplate<
88
88
  }
89
89
 
90
90
  public onEvent(
91
- handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
91
+ handler: (event: Eth, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
92
92
  filter: DeferredTopicFilter | DeferredTopicFilter[],
93
93
  fetchConfig?: EthFetchConfig
94
94
  ) {
@@ -15,7 +15,7 @@ import { BindInternalOptions, BindOptions } from '../core/bind-options.js'
15
15
  import { PromiseOrVoid } from '../promise-or-void.js'
16
16
  import { Trace } from './trace.js'
17
17
  import { ServerError, Status } from 'nice-grpc'
18
- import { EthEvent } from './eth-event.js'
18
+ import { Eth } from './eth.js'
19
19
 
20
20
  export interface AddressOrTypeEventFilter extends DeferredTopicFilter {
21
21
  addressType?: AddressType
@@ -78,7 +78,7 @@ export abstract class BaseProcessor<
78
78
  }
79
79
 
80
80
  public onEvent(
81
- handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
81
+ handler: (event: Eth, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
82
82
  filter: DeferredTopicFilter | DeferredTopicFilter[],
83
83
  fetchConfig?: EthFetchConfig
84
84
  ) {
@@ -120,7 +120,7 @@ export abstract class BaseProcessor<
120
120
  const parsed = contractView.rawContract.interface.parseLog(logParam)
121
121
 
122
122
  if (parsed) {
123
- const event: EthEvent = { ...log, args: parsed.args }
123
+ const event: Eth = { ...log, args: parsed.args }
124
124
  await handler(event, ctx)
125
125
  return ctx.getProcessResult()
126
126
  }
@@ -189,7 +189,7 @@ export abstract class BaseProcessor<
189
189
  return this
190
190
  }
191
191
 
192
- public onAllEvents(handler: (event: EthEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {
192
+ public onAllEvents(handler: (event: Eth, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {
193
193
  const _filters: DeferredTopicFilter[] = []
194
194
  const tmpContract = this.CreateBoundContractView()
195
195
 
@@ -1,6 +1,6 @@
1
1
  import { LogParams } from 'ethers/providers'
2
2
  import { Result } from 'ethers'
3
3
 
4
- export interface EthEvent<TArgsArray extends Array<any> = any, TArgsObject = any> extends LogParams {
4
+ export interface Eth<TArgsArray extends Array<any> = any, TArgsObject = any> extends LogParams {
5
5
  args: TArgsArray & TArgsObject & Result
6
6
  }
package/src/eth/index.ts CHANGED
@@ -5,4 +5,6 @@ export { getProvider, DummyProvider } from './provider.js'
5
5
  export type { TypedCallTrace, Trace } from './trace.js'
6
6
  export { EthPlugin } from './eth-plugin.js'
7
7
 
8
+ export * from './eth.js'
9
+
8
10
  export { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds.js'
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { transformEtherError, EthersError } from './error.js'
1
+ export { transformEtherError, SimpleEthersError } from './error.js'
2
2
 
3
3
  // TODO maybe remove this
4
4
  export * from '@sentio/protos'
@@ -60,19 +60,12 @@ export function generateBoundViewFunction(fn: FunctionDeclaration, includeArgTyp
60
60
  async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
61
61
  useStructs: true,
62
62
  })}overrides?: Overrides): ${generateReturnTypes(fn)} {
63
- try {
64
- if (!overrides && this.context) {
65
- overrides = {
66
- blockTag: toBlockTag(this.context.blockNumber),
67
- }
63
+ if (!overrides && this.context) {
64
+ overrides = {
65
+ blockTag: toBlockTag(this.context.blockNumber),
68
66
  }
69
- return await this.view.${declName}(${
70
- fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
71
- } overrides || {})
72
-
73
- } catch (e) {
74
- throw transformEtherError(e, this.context)
75
67
  }
68
+ return await this.view.${declName}(${fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''} overrides || {})
76
69
  }
77
70
  `
78
71
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=eth-event.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth-event.js","sourceRoot":"","sources":["../../src/eth/eth-event.ts"],"names":[],"mappings":"","sourcesContent":["import { LogParams } from 'ethers/providers'\nimport { Result } from 'ethers'\n\nexport interface EthEvent<TArgsArray extends Array<any> = any, TArgsObject = any> extends LogParams {\n args: TArgsArray & TArgsObject & Result\n}\n"]}