@sentio/sdk 1.8.2 → 1.9.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.
@@ -1,7 +1,7 @@
1
1
  /* Autogenerated file. Do not edit manually. */
2
2
  /* tslint:disable */
3
3
  /* eslint-disable */
4
- import { CallOverrides } from "ethers";
4
+ import { BigNumberish, CallOverrides } from "ethers";
5
5
  import { Networkish } from "@ethersproject/providers";
6
6
  import {
7
7
  addContractByABI,
@@ -18,6 +18,7 @@ import {
18
18
  ContractView,
19
19
  DummyProvider,
20
20
  getContractName,
21
+ TypedTrace,
21
22
  } from "@sentio/sdk";
22
23
  import { PromiseOrValue } from "./common";
23
24
  import { WETH9, WETH9__factory } from "./index";
@@ -304,6 +305,54 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
304
305
  }
305
306
  }
306
307
 
308
+ export interface NameCallTrace extends TypedTrace {
309
+ args: [];
310
+ }
311
+
312
+ export interface ApproveCallTrace extends TypedTrace {
313
+ args: [guy: PromiseOrValue<string>, wad: PromiseOrValue<BigNumberish>];
314
+ }
315
+
316
+ export interface TotalSupplyCallTrace extends TypedTrace {
317
+ args: [];
318
+ }
319
+
320
+ export interface TransferFromCallTrace extends TypedTrace {
321
+ args: [
322
+ src: PromiseOrValue<string>,
323
+ dst: PromiseOrValue<string>,
324
+ wad: PromiseOrValue<BigNumberish>
325
+ ];
326
+ }
327
+
328
+ export interface WithdrawCallTrace extends TypedTrace {
329
+ args: [wad: PromiseOrValue<BigNumberish>];
330
+ }
331
+
332
+ export interface DecimalsCallTrace extends TypedTrace {
333
+ args: [];
334
+ }
335
+
336
+ export interface BalanceOfCallTrace extends TypedTrace {
337
+ args: [arg0: PromiseOrValue<string>];
338
+ }
339
+
340
+ export interface SymbolCallTrace extends TypedTrace {
341
+ args: [];
342
+ }
343
+
344
+ export interface TransferCallTrace extends TypedTrace {
345
+ args: [dst: PromiseOrValue<string>, wad: PromiseOrValue<BigNumberish>];
346
+ }
347
+
348
+ export interface DepositCallTrace extends TypedTrace {
349
+ args: [];
350
+ }
351
+
352
+ export interface AllowanceCallTrace extends TypedTrace {
353
+ args: [arg0: PromiseOrValue<string>, arg1: PromiseOrValue<string>];
354
+ }
355
+
307
356
  export class WETH9Processor extends BaseProcessor<
308
357
  WETH9,
309
358
  WETH9BoundContractView
@@ -359,6 +408,64 @@ export class WETH9Processor extends BaseProcessor<
359
408
  return super.onEvent(handler, filter);
360
409
  }
361
410
 
411
+ onNameCall(handler: (trace: NameCallTrace, ctx: WETH9Context) => void) {
412
+ return super.onTrace("name()", handler);
413
+ }
414
+
415
+ onApproveCall(handler: (trace: ApproveCallTrace, ctx: WETH9Context) => void) {
416
+ return super.onTrace("approve(address,uint256)", handler);
417
+ }
418
+
419
+ onTotalSupplyCall(
420
+ handler: (trace: TotalSupplyCallTrace, ctx: WETH9Context) => void
421
+ ) {
422
+ return super.onTrace("totalSupply()", handler);
423
+ }
424
+
425
+ onTransferFromCall(
426
+ handler: (trace: TransferFromCallTrace, ctx: WETH9Context) => void
427
+ ) {
428
+ return super.onTrace("transferFrom(address,address,uint256)", handler);
429
+ }
430
+
431
+ onWithdrawCall(
432
+ handler: (trace: WithdrawCallTrace, ctx: WETH9Context) => void
433
+ ) {
434
+ return super.onTrace("withdraw(uint256)", handler);
435
+ }
436
+
437
+ onDecimalsCall(
438
+ handler: (trace: DecimalsCallTrace, ctx: WETH9Context) => void
439
+ ) {
440
+ return super.onTrace("decimals()", handler);
441
+ }
442
+
443
+ onBalanceOfCall(
444
+ handler: (trace: BalanceOfCallTrace, ctx: WETH9Context) => void
445
+ ) {
446
+ return super.onTrace("balanceOf(address)", handler);
447
+ }
448
+
449
+ onSymbolCall(handler: (trace: SymbolCallTrace, ctx: WETH9Context) => void) {
450
+ return super.onTrace("symbol()", handler);
451
+ }
452
+
453
+ onTransferCall(
454
+ handler: (trace: TransferCallTrace, ctx: WETH9Context) => void
455
+ ) {
456
+ return super.onTrace("transfer(address,uint256)", handler);
457
+ }
458
+
459
+ onDepositCall(handler: (trace: DepositCallTrace, ctx: WETH9Context) => void) {
460
+ return super.onTrace("deposit()", handler);
461
+ }
462
+
463
+ onAllowanceCall(
464
+ handler: (trace: AllowanceCallTrace, ctx: WETH9Context) => void
465
+ ) {
466
+ return super.onTrace("allowance(address,address)", handler);
467
+ }
468
+
362
469
  public static filters = templateContract.filters;
363
470
 
364
471
  protected CreateBoundContractView(): WETH9BoundContractView {
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export { transformEtherError } from './error'
12
12
  export { ProcessorState } from './processor-state'
13
13
  export { BigNumber as BigDecimal } from 'bignumber.js'
14
14
  export { EthersError } from './error'
15
+ export type { TypedTrace } from './trace'
15
16
 
16
17
  export { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'
17
18
 
@@ -9,6 +9,7 @@ import {
9
9
  import { reservedKeywords } from '@typechain/ethers-v5/dist/codegen/reserved-keywords'
10
10
  import { generateInputTypes } from '@typechain/ethers-v5/dist/codegen/types'
11
11
  import { getFullSignatureForEvent } from 'typechain/dist/utils/signatures'
12
+ import { codegenCallTraceTypes, codegenFunctions } from './functions'
12
13
 
13
14
  export function codeGenIndex(contract: Contract): string {
14
15
  return `
@@ -72,6 +73,8 @@ export function codeGenSentioFile(contract: Contract): string {
72
73
  .join('\n')}
73
74
  }
74
75
 
76
+ ${Object.values(contract.functions).map(codegenCallTraceTypes).join('\n')}
77
+
75
78
  export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {
76
79
  ${Object.values(contract.events)
77
80
  .map((events) => {
@@ -83,6 +86,10 @@ export function codeGenSentioFile(contract: Contract): string {
83
86
  })
84
87
  .join('\n')}
85
88
 
89
+ ${Object.values(contract.functions)
90
+ .map((f) => codegenFunctions(f, contract.name))
91
+ .join('\n')}
92
+
86
93
  public static filters = templateContract.filters
87
94
 
88
95
  protected CreateBoundContractView(): ${contract.name}BoundContractView {
@@ -134,6 +141,7 @@ export function codeGenSentioFile(contract: Contract): string {
134
141
  'ContractView',
135
142
  'DummyProvider',
136
143
  'getContractName',
144
+ 'TypedTrace',
137
145
  ],
138
146
  './common': ['PromiseOrValue'],
139
147
  './index': [`${contract.name}`, `${contract.name}__factory`],
@@ -0,0 +1,55 @@
1
+ import { generateInputTypes } from '@typechain/ethers-v5/dist/codegen/types'
2
+ import { FunctionDeclaration, getSignatureForFn } from 'typechain'
3
+
4
+ export function codegenFunctions(fns: FunctionDeclaration[], contractName: string): string {
5
+ if (fns.length === 1) {
6
+ return generateFunction(fns[0], contractName)
7
+ }
8
+
9
+ return fns.map((fn) => generateFunction(fn, contractName, getFullSignatureAsSymbolForFunction(fn))).join('\n')
10
+ }
11
+
12
+ export function codegenCallTraceTypes(fns: FunctionDeclaration[]): string {
13
+ if (fns.length === 1) {
14
+ return codegenCallTraceType(fns[0])
15
+ }
16
+
17
+ return fns.map((fn) => codegenCallTraceType(fn, getFullSignatureAsSymbolForFunction(fn))).join('\n')
18
+ }
19
+
20
+ function codegenCallTraceType(fn: FunctionDeclaration, overloadedName?: string): string {
21
+ return `
22
+ export interface ${capitalizeFirstChar(overloadedName ?? fn.name)}CallTrace extends TypedTrace {
23
+ args: [${generateInputTypes(fn.inputs, { useStructs: true })}]
24
+ }
25
+ `
26
+ }
27
+
28
+ function generateFunction(fn: FunctionDeclaration, contractName: string, overloadedName?: string): string {
29
+ return `
30
+ on${capitalizeFirstChar(overloadedName ?? fn.name)}Call(
31
+ handler: (trace: ${capitalizeFirstChar(overloadedName ?? fn.name)}CallTrace, ctx: ${contractName}Context) => void
32
+ ) {
33
+ return super.onTrace("${getSignatureForFn(fn)}", handler);
34
+ }
35
+ `
36
+ }
37
+
38
+ function getFullSignatureAsSymbolForFunction(fn: FunctionDeclaration): string {
39
+ return `${fn.name}_${fn.inputs
40
+ .map((e) => {
41
+ if (e.type.type === 'array') {
42
+ return e.type.itemType.originalType + '_array'
43
+ } else {
44
+ return e.type.originalType
45
+ }
46
+ })
47
+ .join('_')}`
48
+ }
49
+
50
+ function capitalizeFirstChar(input: string): string {
51
+ if (!input) {
52
+ return input
53
+ }
54
+ return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')
55
+ }