@sentio/sdk 2.18.0 → 2.18.1-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 (40) hide show
  1. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +49 -23
  2. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  3. package/lib/eth/builtin/internal/erc1155-processor.js +19 -8
  4. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  5. package/lib/eth/builtin/internal/erc20-processor.js +39 -18
  6. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  7. package/lib/eth/builtin/internal/erc20bytes-processor.js +21 -9
  8. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  9. package/lib/eth/builtin/internal/erc721-processor.js +31 -14
  10. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  11. package/lib/eth/builtin/internal/weth9-processor.js +25 -11
  12. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  13. package/lib/eth/codegen/file.js +4 -1
  14. package/lib/eth/codegen/file.js.map +1 -1
  15. package/lib/eth/codegen/function-calls.js +2 -1
  16. package/lib/eth/codegen/function-calls.js.map +1 -1
  17. package/lib/eth/eth.d.ts +2 -2
  18. package/lib/eth/eth.js +12 -13
  19. package/lib/eth/eth.js.map +1 -1
  20. package/lib/eth/provider.js +1 -1
  21. package/lib/eth/provider.js.map +1 -1
  22. package/lib/utils/call.d.ts +6 -0
  23. package/lib/utils/call.js +21 -0
  24. package/lib/utils/call.js.map +1 -0
  25. package/lib/utils/index.d.ts +1 -0
  26. package/lib/utils/index.js +1 -0
  27. package/lib/utils/index.js.map +1 -1
  28. package/package.json +3 -3
  29. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +50 -24
  30. package/src/eth/builtin/internal/erc1155-processor.ts +20 -9
  31. package/src/eth/builtin/internal/erc20-processor.ts +40 -19
  32. package/src/eth/builtin/internal/erc20bytes-processor.ts +22 -10
  33. package/src/eth/builtin/internal/erc721-processor.ts +32 -15
  34. package/src/eth/builtin/internal/weth9-processor.ts +26 -12
  35. package/src/eth/codegen/file.ts +4 -1
  36. package/src/eth/codegen/function-calls.ts +2 -1
  37. package/src/eth/eth.ts +11 -13
  38. package/src/eth/provider.ts +1 -1
  39. package/src/utils/call.ts +20 -0
  40. package/src/utils/index.ts +1 -0
@@ -112,45 +112,50 @@ export class WETH9ContractView extends ContractView<WETH9> {
112
112
  }
113
113
 
114
114
  async name(overrides?: Overrides): Promise<string> {
115
+ const stack = new Error().stack;
115
116
  try {
116
117
  return await this.contract.getFunction("name()")(overrides || {});
117
118
  } catch (e) {
118
- throw transformEtherError(e, undefined);
119
+ throw transformEtherError(e, undefined, stack);
119
120
  }
120
121
  }
121
122
 
122
123
  async totalSupply(overrides?: Overrides): Promise<bigint> {
124
+ const stack = new Error().stack;
123
125
  try {
124
126
  return await this.contract.getFunction("totalSupply()")(overrides || {});
125
127
  } catch (e) {
126
- throw transformEtherError(e, undefined);
128
+ throw transformEtherError(e, undefined, stack);
127
129
  }
128
130
  }
129
131
 
130
132
  async decimals(overrides?: Overrides): Promise<bigint> {
133
+ const stack = new Error().stack;
131
134
  try {
132
135
  return await this.contract.getFunction("decimals()")(overrides || {});
133
136
  } catch (e) {
134
- throw transformEtherError(e, undefined);
137
+ throw transformEtherError(e, undefined, stack);
135
138
  }
136
139
  }
137
140
 
138
141
  async balanceOf(arg0: string, overrides?: Overrides): Promise<bigint> {
142
+ const stack = new Error().stack;
139
143
  try {
140
144
  return await this.contract.getFunction("balanceOf(address)")(
141
145
  arg0,
142
146
  overrides || {}
143
147
  );
144
148
  } catch (e) {
145
- throw transformEtherError(e, undefined);
149
+ throw transformEtherError(e, undefined, stack);
146
150
  }
147
151
  }
148
152
 
149
153
  async symbol(overrides?: Overrides): Promise<string> {
154
+ const stack = new Error().stack;
150
155
  try {
151
156
  return await this.contract.getFunction("symbol()")(overrides || {});
152
157
  } catch (e) {
153
- throw transformEtherError(e, undefined);
158
+ throw transformEtherError(e, undefined, stack);
154
159
  }
155
160
  }
156
161
 
@@ -159,6 +164,7 @@ export class WETH9ContractView extends ContractView<WETH9> {
159
164
  arg1: string,
160
165
  overrides?: Overrides
161
166
  ): Promise<bigint> {
167
+ const stack = new Error().stack;
162
168
  try {
163
169
  return await this.contract.getFunction("allowance(address,address)")(
164
170
  arg0,
@@ -166,7 +172,7 @@ export class WETH9ContractView extends ContractView<WETH9> {
166
172
  overrides || {}
167
173
  );
168
174
  } catch (e) {
169
- throw transformEtherError(e, undefined);
175
+ throw transformEtherError(e, undefined, stack);
170
176
  }
171
177
  }
172
178
 
@@ -178,12 +184,13 @@ export class WETH9ContractView extends ContractView<WETH9> {
178
184
  wad: BigNumberish,
179
185
  overrides?: Overrides
180
186
  ): Promise<boolean> {
187
+ const stack = new Error().stack;
181
188
  try {
182
189
  return await this.contract
183
190
  .getFunction("approve(address,uint256)")
184
191
  .staticCall(guy, wad, overrides || {});
185
192
  } catch (e) {
186
- throw transformEtherError(e, undefined);
193
+ throw transformEtherError(e, undefined, stack);
187
194
  }
188
195
  },
189
196
  async transferFrom(
@@ -192,21 +199,23 @@ export class WETH9ContractView extends ContractView<WETH9> {
192
199
  wad: BigNumberish,
193
200
  overrides?: Overrides
194
201
  ): Promise<boolean> {
202
+ const stack = new Error().stack;
195
203
  try {
196
204
  return await this.contract
197
205
  .getFunction("transferFrom(address,address,uint256)")
198
206
  .staticCall(src, dst, wad, overrides || {});
199
207
  } catch (e) {
200
- throw transformEtherError(e, undefined);
208
+ throw transformEtherError(e, undefined, stack);
201
209
  }
202
210
  },
203
211
  async withdraw(wad: BigNumberish, overrides?: Overrides): Promise<void> {
212
+ const stack = new Error().stack;
204
213
  try {
205
214
  return await this.contract
206
215
  .getFunction("withdraw(uint256)")
207
216
  .staticCall(wad, overrides || {});
208
217
  } catch (e) {
209
- throw transformEtherError(e, undefined);
218
+ throw transformEtherError(e, undefined, stack);
210
219
  }
211
220
  },
212
221
  async transfer(
@@ -214,21 +223,23 @@ export class WETH9ContractView extends ContractView<WETH9> {
214
223
  wad: BigNumberish,
215
224
  overrides?: Overrides
216
225
  ): Promise<boolean> {
226
+ const stack = new Error().stack;
217
227
  try {
218
228
  return await this.contract
219
229
  .getFunction("transfer(address,uint256)")
220
230
  .staticCall(dst, wad, overrides || {});
221
231
  } catch (e) {
222
- throw transformEtherError(e, undefined);
232
+ throw transformEtherError(e, undefined, stack);
223
233
  }
224
234
  },
225
235
  async deposit(overrides?: Overrides): Promise<void> {
236
+ const stack = new Error().stack;
226
237
  try {
227
238
  return await this.contract
228
239
  .getFunction("deposit()")
229
240
  .staticCall(overrides || {});
230
241
  } catch (e) {
231
- throw transformEtherError(e, undefined);
242
+ throw transformEtherError(e, undefined, stack);
232
243
  }
233
244
  },
234
245
  };
@@ -608,6 +619,9 @@ export function getWETH9ContractOnContext(
608
619
  ): WETH9BoundContractView {
609
620
  const view = getWETH9Contract(context.getChainId(), address);
610
621
  const boundView = new WETH9BoundContractView(address, view);
611
- boundView.context = context as any;
622
+ boundView.context = context;
623
+ if (boundView.callStatic) {
624
+ boundView.callStatic.context = context;
625
+ }
612
626
  return boundView;
613
627
  }
@@ -138,7 +138,10 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
138
138
  ${contract.name}BoundContractView {
139
139
  const view = get${contract.name}Contract(context.getChainId(), address)
140
140
  const boundView = new ${contract.name}BoundContractView(address, view)
141
- boundView.context = context as any;
141
+ boundView.context = context;
142
+ if (boundView.callStatic) {
143
+ boundView.callStatic.context = context;
144
+ }
142
145
  return boundView;
143
146
  }
144
147
  `
@@ -35,12 +35,13 @@ export function generateViewFunction(view: boolean, fn: FunctionDeclaration, inc
35
35
  async ${declName}(${generateInputTypes(fn.inputs, {
36
36
  useStructs: true,
37
37
  })}overrides?: Overrides): ${generateReturnTypes(fn)} {
38
+ const stack = new Error().stack
38
39
  try {
39
40
  return await ${func}${call}(${
40
41
  fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
41
42
  } overrides || {})
42
43
  } catch (e) {
43
- throw transformEtherError(e, undefined)
44
+ throw transformEtherError(e, undefined, stack)
44
45
  }
45
46
  }
46
47
  `,
package/src/eth/eth.ts CHANGED
@@ -42,9 +42,9 @@ export interface RichBlock extends BlockParams {
42
42
  export class SimpleEthersError extends Error {
43
43
  e: Error
44
44
 
45
- constructor(message: string, e: Error) {
45
+ constructor(message: string, e: Error, stack?: string) {
46
46
  super(message)
47
- this.stack = e.stack
47
+ this.stack = stack
48
48
  }
49
49
 
50
50
  toString() {
@@ -52,7 +52,7 @@ export class SimpleEthersError extends Error {
52
52
  }
53
53
  }
54
54
 
55
- export function transformEtherError(e: Error, ctx: ContractContext<any, any> | undefined): Error {
55
+ export function transformEtherError(e: Error, ctx: ContractContext<any, any> | undefined, stack?: string): Error {
56
56
  if (e instanceof SimpleEthersError) {
57
57
  return e
58
58
  }
@@ -62,23 +62,21 @@ export function transformEtherError(e: Error, ctx: ContractContext<any, any> | u
62
62
 
63
63
  let msg = ''
64
64
  const err = e as CallExceptionError
65
- if (err.code === 'CALL_EXCEPTION') {
65
+ if (err.code === 'CALL_EXCEPTION' || err.code === 'BAD_DATA') {
66
+ const stack = new Error().stack
66
67
  if (err.data === '0x') {
67
68
  if (ctx) {
68
- msg =
69
- "jsonrpc eth_call return '0x' (likely contract not existed) at chain " +
70
- ctx.chainId +
71
- ': ' +
72
- JSON.stringify(e)
69
+ msg = `jsonrpc eth_call return '0x' (likely contract not existed) at chain ${ctx.chainId}, ${checkPage}:\n${e.message}`
73
70
  } else {
74
- msg = "jsonrpc eth_call return '0x' (likely contract not existed): " + JSON.stringify(err)
71
+ msg = `jsonrpc eth_call return '0x' (likely contract not existed), ${checkPage}:\n${e.message}`
75
72
  }
76
- msg += '\n' + checkPage
77
- return new SimpleEthersError(msg, err)
73
+ return new SimpleEthersError(msg, err, stack)
74
+ } else {
75
+ return new SimpleEthersError(`eth call error, ${checkPage}:\nerr.message`, err, stack)
78
76
  }
79
77
  }
80
78
 
81
- msg = 'ethers call error\n' + JSON.stringify(e) + '\n' + e.stack?.toString() + '\n' + checkPage
79
+ msg = 'other error during call error\n' + JSON.stringify(e) + '\n' + stack?.toString() + '\n' + checkPage
82
80
  return new Error(msg)
83
81
  }
84
82
 
@@ -97,7 +97,7 @@ class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
97
97
  if (!perform) {
98
98
  perform = this.executor.add(() => super.send(method, params))
99
99
  perform.catch((e) => {
100
- if (e.code !== 'CALL_EXCEPTION') {
100
+ if (e.code !== 'CALL_EXCEPTION' && e.code !== 'BAD_DATA') {
101
101
  setTimeout(() => {
102
102
  if (this.#performCache.get(tag) === perform) {
103
103
  this.#performCache.delete(tag)
@@ -0,0 +1,20 @@
1
+ import { SimpleEthersError } from '../eth/index.js'
2
+
3
+ /**
4
+ * ignore eth call exception and return undefined if that happened
5
+ * @param promise promise return by eth call
6
+ * @param logError whether to log error
7
+ */
8
+ export async function ignoreEthCallException<Res>(promise: Promise<Res>, logError = false): Promise<Res | undefined> {
9
+ try {
10
+ return await promise
11
+ } catch (err) {
12
+ if (err instanceof SimpleEthersError || err.code === 'CALL_EXCEPTION' || err.code === 'BAD_DATA') {
13
+ if (logError) {
14
+ console.error('eth call exception, return undefined', err)
15
+ }
16
+ return undefined
17
+ }
18
+ throw err
19
+ }
20
+ }
@@ -2,3 +2,4 @@ export * from './conversion.js'
2
2
  export * as token from './token.js'
3
3
  export * from './dex-price.js'
4
4
  export { getPriceByType, getPriceClient, getPriceBySymbol } from './price.js'
5
+ export * from './call.js'