@sentio/sdk 2.18.1-rc.9 → 2.18.2-rc.1

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 (29) hide show
  1. package/lib/eth/base-processor-template.js +1 -1
  2. package/lib/eth/base-processor-template.js.map +1 -1
  3. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +46 -23
  4. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  5. package/lib/eth/builtin/internal/erc1155-processor.js +16 -8
  6. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  7. package/lib/eth/builtin/internal/erc20-processor.js +36 -18
  8. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  9. package/lib/eth/builtin/internal/erc20bytes-processor.js +18 -9
  10. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  11. package/lib/eth/builtin/internal/erc721-processor.js +28 -14
  12. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  13. package/lib/eth/builtin/internal/weth9-processor.js +22 -11
  14. package/lib/eth/builtin/internal/weth9-processor.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 +8 -13
  19. package/lib/eth/eth.js.map +1 -1
  20. package/package.json +3 -3
  21. package/src/eth/base-processor-template.ts +1 -1
  22. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +46 -23
  23. package/src/eth/builtin/internal/erc1155-processor.ts +16 -8
  24. package/src/eth/builtin/internal/erc20-processor.ts +36 -18
  25. package/src/eth/builtin/internal/erc20bytes-processor.ts +18 -9
  26. package/src/eth/builtin/internal/erc721-processor.ts +28 -14
  27. package/src/eth/builtin/internal/weth9-processor.ts +22 -11
  28. package/src/eth/codegen/function-calls.ts +2 -1
  29. package/src/eth/eth.ts +8 -13
@@ -103,45 +103,50 @@ export class ERC20BytesContractView extends ContractView<ERC20Bytes> {
103
103
  }
104
104
 
105
105
  async name(overrides?: Overrides): Promise<string> {
106
+ const stack = new Error().stack;
106
107
  try {
107
108
  return await this.contract.getFunction("name()")(overrides || {});
108
109
  } catch (e) {
109
- throw transformEtherError(e, undefined);
110
+ throw transformEtherError(e, undefined, stack);
110
111
  }
111
112
  }
112
113
 
113
114
  async totalSupply(overrides?: Overrides): Promise<bigint> {
115
+ const stack = new Error().stack;
114
116
  try {
115
117
  return await this.contract.getFunction("totalSupply()")(overrides || {});
116
118
  } catch (e) {
117
- throw transformEtherError(e, undefined);
119
+ throw transformEtherError(e, undefined, stack);
118
120
  }
119
121
  }
120
122
 
121
123
  async decimals(overrides?: Overrides): Promise<bigint> {
124
+ const stack = new Error().stack;
122
125
  try {
123
126
  return await this.contract.getFunction("decimals()")(overrides || {});
124
127
  } catch (e) {
125
- throw transformEtherError(e, undefined);
128
+ throw transformEtherError(e, undefined, stack);
126
129
  }
127
130
  }
128
131
 
129
132
  async balanceOf(who: string, overrides?: Overrides): Promise<bigint> {
133
+ const stack = new Error().stack;
130
134
  try {
131
135
  return await this.contract.getFunction("balanceOf(address)")(
132
136
  who,
133
137
  overrides || {}
134
138
  );
135
139
  } catch (e) {
136
- throw transformEtherError(e, undefined);
140
+ throw transformEtherError(e, undefined, stack);
137
141
  }
138
142
  }
139
143
 
140
144
  async symbol(overrides?: Overrides): Promise<string> {
145
+ const stack = new Error().stack;
141
146
  try {
142
147
  return await this.contract.getFunction("symbol()")(overrides || {});
143
148
  } catch (e) {
144
- throw transformEtherError(e, undefined);
149
+ throw transformEtherError(e, undefined, stack);
145
150
  }
146
151
  }
147
152
 
@@ -150,6 +155,7 @@ export class ERC20BytesContractView extends ContractView<ERC20Bytes> {
150
155
  spender: string,
151
156
  overrides?: Overrides
152
157
  ): Promise<bigint> {
158
+ const stack = new Error().stack;
153
159
  try {
154
160
  return await this.contract.getFunction("allowance(address,address)")(
155
161
  owner,
@@ -157,7 +163,7 @@ export class ERC20BytesContractView extends ContractView<ERC20Bytes> {
157
163
  overrides || {}
158
164
  );
159
165
  } catch (e) {
160
- throw transformEtherError(e, undefined);
166
+ throw transformEtherError(e, undefined, stack);
161
167
  }
162
168
  }
163
169
 
@@ -169,12 +175,13 @@ export class ERC20BytesContractView extends ContractView<ERC20Bytes> {
169
175
  value: BigNumberish,
170
176
  overrides?: Overrides
171
177
  ): Promise<boolean> {
178
+ const stack = new Error().stack;
172
179
  try {
173
180
  return await this.contract
174
181
  .getFunction("approve(address,uint256)")
175
182
  .staticCall(spender, value, overrides || {});
176
183
  } catch (e) {
177
- throw transformEtherError(e, undefined);
184
+ throw transformEtherError(e, undefined, stack);
178
185
  }
179
186
  },
180
187
  async transferFrom(
@@ -183,12 +190,13 @@ export class ERC20BytesContractView extends ContractView<ERC20Bytes> {
183
190
  value: BigNumberish,
184
191
  overrides?: Overrides
185
192
  ): Promise<boolean> {
193
+ const stack = new Error().stack;
186
194
  try {
187
195
  return await this.contract
188
196
  .getFunction("transferFrom(address,address,uint256)")
189
197
  .staticCall(from, to, value, overrides || {});
190
198
  } catch (e) {
191
- throw transformEtherError(e, undefined);
199
+ throw transformEtherError(e, undefined, stack);
192
200
  }
193
201
  },
194
202
  async transfer(
@@ -196,12 +204,13 @@ export class ERC20BytesContractView extends ContractView<ERC20Bytes> {
196
204
  value: BigNumberish,
197
205
  overrides?: Overrides
198
206
  ): Promise<boolean> {
207
+ const stack = new Error().stack;
199
208
  try {
200
209
  return await this.contract
201
210
  .getFunction("transfer(address,uint256)")
202
211
  .staticCall(to, value, overrides || {});
203
212
  } catch (e) {
204
- throw transformEtherError(e, undefined);
213
+ throw transformEtherError(e, undefined, stack);
205
214
  }
206
215
  },
207
216
  };
@@ -155,21 +155,23 @@ export class ERC721ContractView extends ContractView<ERC721> {
155
155
  }
156
156
 
157
157
  async totalSupply(overrides?: Overrides): Promise<bigint> {
158
+ const stack = new Error().stack;
158
159
  try {
159
160
  return await this.contract.getFunction("totalSupply()")(overrides || {});
160
161
  } catch (e) {
161
- throw transformEtherError(e, undefined);
162
+ throw transformEtherError(e, undefined, stack);
162
163
  }
163
164
  }
164
165
 
165
166
  async balanceOf(owner: string, overrides?: Overrides): Promise<bigint> {
167
+ const stack = new Error().stack;
166
168
  try {
167
169
  return await this.contract.getFunction("balanceOf(address)")(
168
170
  owner,
169
171
  overrides || {}
170
172
  );
171
173
  } catch (e) {
172
- throw transformEtherError(e, undefined);
174
+ throw transformEtherError(e, undefined, stack);
173
175
  }
174
176
  }
175
177
 
@@ -177,13 +179,14 @@ export class ERC721ContractView extends ContractView<ERC721> {
177
179
  tokenId: BigNumberish,
178
180
  overrides?: Overrides
179
181
  ): Promise<string> {
182
+ const stack = new Error().stack;
180
183
  try {
181
184
  return await this.contract.getFunction("getApproved(uint256)")(
182
185
  tokenId,
183
186
  overrides || {}
184
187
  );
185
188
  } catch (e) {
186
- throw transformEtherError(e, undefined);
189
+ throw transformEtherError(e, undefined, stack);
187
190
  }
188
191
  }
189
192
 
@@ -192,31 +195,34 @@ export class ERC721ContractView extends ContractView<ERC721> {
192
195
  operator: string,
193
196
  overrides?: Overrides
194
197
  ): Promise<boolean> {
198
+ const stack = new Error().stack;
195
199
  try {
196
200
  return await this.contract.getFunction(
197
201
  "isApprovedForAll(address,address)"
198
202
  )(owner, operator, overrides || {});
199
203
  } catch (e) {
200
- throw transformEtherError(e, undefined);
204
+ throw transformEtherError(e, undefined, stack);
201
205
  }
202
206
  }
203
207
 
204
208
  async name(overrides?: Overrides): Promise<string> {
209
+ const stack = new Error().stack;
205
210
  try {
206
211
  return await this.contract.getFunction("name()")(overrides || {});
207
212
  } catch (e) {
208
- throw transformEtherError(e, undefined);
213
+ throw transformEtherError(e, undefined, stack);
209
214
  }
210
215
  }
211
216
 
212
217
  async ownerOf(tokenId: BigNumberish, overrides?: Overrides): Promise<string> {
218
+ const stack = new Error().stack;
213
219
  try {
214
220
  return await this.contract.getFunction("ownerOf(uint256)")(
215
221
  tokenId,
216
222
  overrides || {}
217
223
  );
218
224
  } catch (e) {
219
- throw transformEtherError(e, undefined);
225
+ throw transformEtherError(e, undefined, stack);
220
226
  }
221
227
  }
222
228
 
@@ -224,21 +230,23 @@ export class ERC721ContractView extends ContractView<ERC721> {
224
230
  interfaceId: BytesLike,
225
231
  overrides?: Overrides
226
232
  ): Promise<boolean> {
233
+ const stack = new Error().stack;
227
234
  try {
228
235
  return await this.contract.getFunction("supportsInterface(bytes4)")(
229
236
  interfaceId,
230
237
  overrides || {}
231
238
  );
232
239
  } catch (e) {
233
- throw transformEtherError(e, undefined);
240
+ throw transformEtherError(e, undefined, stack);
234
241
  }
235
242
  }
236
243
 
237
244
  async symbol(overrides?: Overrides): Promise<string> {
245
+ const stack = new Error().stack;
238
246
  try {
239
247
  return await this.contract.getFunction("symbol()")(overrides || {});
240
248
  } catch (e) {
241
- throw transformEtherError(e, undefined);
249
+ throw transformEtherError(e, undefined, stack);
242
250
  }
243
251
  }
244
252
 
@@ -246,13 +254,14 @@ export class ERC721ContractView extends ContractView<ERC721> {
246
254
  tokenId: BigNumberish,
247
255
  overrides?: Overrides
248
256
  ): Promise<string> {
257
+ const stack = new Error().stack;
249
258
  try {
250
259
  return await this.contract.getFunction("tokenURI(uint256)")(
251
260
  tokenId,
252
261
  overrides || {}
253
262
  );
254
263
  } catch (e) {
255
- throw transformEtherError(e, undefined);
264
+ throw transformEtherError(e, undefined, stack);
256
265
  }
257
266
  }
258
267
 
@@ -264,12 +273,13 @@ export class ERC721ContractView extends ContractView<ERC721> {
264
273
  tokenId: BigNumberish,
265
274
  overrides?: Overrides
266
275
  ): Promise<void> {
276
+ const stack = new Error().stack;
267
277
  try {
268
278
  return await this.contract
269
279
  .getFunction("approve(address,uint256)")
270
280
  .staticCall(to, tokenId, overrides || {});
271
281
  } catch (e) {
272
- throw transformEtherError(e, undefined);
282
+ throw transformEtherError(e, undefined, stack);
273
283
  }
274
284
  },
275
285
  async safeTransferFrom_address_address_uint256(
@@ -278,12 +288,13 @@ export class ERC721ContractView extends ContractView<ERC721> {
278
288
  tokenId: BigNumberish,
279
289
  overrides?: Overrides
280
290
  ): Promise<void> {
291
+ const stack = new Error().stack;
281
292
  try {
282
293
  return await this.contract
283
294
  .getFunction("safeTransferFrom(address,address,uint256)")
284
295
  .staticCall(from, to, tokenId, overrides || {});
285
296
  } catch (e) {
286
- throw transformEtherError(e, undefined);
297
+ throw transformEtherError(e, undefined, stack);
287
298
  }
288
299
  },
289
300
  async safeTransferFrom_address_address_uint256_bytes(
@@ -293,12 +304,13 @@ export class ERC721ContractView extends ContractView<ERC721> {
293
304
  data: BytesLike,
294
305
  overrides?: Overrides
295
306
  ): Promise<void> {
307
+ const stack = new Error().stack;
296
308
  try {
297
309
  return await this.contract
298
310
  .getFunction("safeTransferFrom(address,address,uint256,bytes)")
299
311
  .staticCall(from, to, tokenId, data, overrides || {});
300
312
  } catch (e) {
301
- throw transformEtherError(e, undefined);
313
+ throw transformEtherError(e, undefined, stack);
302
314
  }
303
315
  },
304
316
  async setApprovalForAll(
@@ -306,12 +318,13 @@ export class ERC721ContractView extends ContractView<ERC721> {
306
318
  _approved: boolean,
307
319
  overrides?: Overrides
308
320
  ): Promise<void> {
321
+ const stack = new Error().stack;
309
322
  try {
310
323
  return await this.contract
311
324
  .getFunction("setApprovalForAll(address,bool)")
312
325
  .staticCall(operator, _approved, overrides || {});
313
326
  } catch (e) {
314
- throw transformEtherError(e, undefined);
327
+ throw transformEtherError(e, undefined, stack);
315
328
  }
316
329
  },
317
330
  async transferFrom(
@@ -320,12 +333,13 @@ export class ERC721ContractView extends ContractView<ERC721> {
320
333
  tokenId: BigNumberish,
321
334
  overrides?: Overrides
322
335
  ): Promise<void> {
336
+ const stack = new Error().stack;
323
337
  try {
324
338
  return await this.contract
325
339
  .getFunction("transferFrom(address,address,uint256)")
326
340
  .staticCall(from, to, tokenId, overrides || {});
327
341
  } catch (e) {
328
- throw transformEtherError(e, undefined);
342
+ throw transformEtherError(e, undefined, stack);
329
343
  }
330
344
  },
331
345
  };
@@ -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
  };
@@ -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
  }
@@ -65,22 +65,17 @@ export function transformEtherError(e: Error, ctx: ContractContext<any, any> | u
65
65
  if (err.code === 'CALL_EXCEPTION' || err.code === 'BAD_DATA') {
66
66
  if (err.data === '0x') {
67
67
  if (ctx) {
68
- msg =
69
- "jsonrpc eth_call return '0x' (likely contract not existed) at chain " +
70
- ctx.chainId +
71
- ': ' +
72
- JSON.stringify(e)
68
+ msg = `jsonrpc eth_call return '0x' (likely contract not existed) at chain ${ctx.chainId}, ${checkPage}:\n${e.message}`
73
69
  } else {
74
- msg = "jsonrpc eth_call return '0x' (likely contract not existed): " + JSON.stringify(err)
70
+ msg = `jsonrpc eth_call return '0x' (likely contract not existed), ${checkPage}:\n${e.message}`
75
71
  }
76
- msg += '\n' + checkPage
77
- return new SimpleEthersError(msg, err)
72
+ return new SimpleEthersError(msg, err, stack)
78
73
  } else {
79
- return new SimpleEthersError('eth call error, ' + checkPage, err)
74
+ return new SimpleEthersError(`eth call error, ${checkPage}:\nerr.message`, err, stack)
80
75
  }
81
76
  }
82
77
 
83
- msg = 'other error during call error\n' + JSON.stringify(e) + '\n' + e.stack?.toString() + '\n' + checkPage
78
+ msg = 'other error during call error\n' + JSON.stringify(e) + '\n' + stack?.toString() + '\n' + checkPage
84
79
  return new Error(msg)
85
80
  }
86
81