@0xtorch/evm 0.0.52 → 0.0.53

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 (72) hide show
  1. package/_cjs/clients/externals/viem/createViemInstance.js +2 -1
  2. package/_cjs/clients/externals/viem/createViemInstance.js.map +1 -1
  3. package/_cjs/decoder/tests.js +3 -0
  4. package/_cjs/decoder/tests.js.map +1 -1
  5. package/_cjs/explorers/definitions/blockscout.js +22 -0
  6. package/_cjs/explorers/definitions/blockscout.js.map +1 -1
  7. package/_cjs/explorers/definitions/etherscan.js +23 -0
  8. package/_cjs/explorers/definitions/etherscan.js.map +1 -1
  9. package/_cjs/explorers/definitions/roninExplorer.js +6 -0
  10. package/_cjs/explorers/definitions/roninExplorer.js.map +1 -1
  11. package/_cjs/explorers/definitions/routescan.js +4 -0
  12. package/_cjs/explorers/definitions/routescan.js.map +1 -1
  13. package/_cjs/explorers/externals/blockscout/getEventLogsByAddressAndTopics.js +76 -0
  14. package/_cjs/explorers/externals/blockscout/getEventLogsByAddressAndTopics.js.map +1 -0
  15. package/_cjs/explorers/externals/blockscout/index.js +3 -1
  16. package/_cjs/explorers/externals/blockscout/index.js.map +1 -1
  17. package/_cjs/explorers/externals/etherscan/getEventLogsByAddressAndTopics.js +77 -0
  18. package/_cjs/explorers/externals/etherscan/getEventLogsByAddressAndTopics.js.map +1 -0
  19. package/_cjs/explorers/externals/etherscan/index.js +3 -1
  20. package/_cjs/explorers/externals/etherscan/index.js.map +1 -1
  21. package/_esm/clients/externals/viem/createViemInstance.js +4 -2
  22. package/_esm/clients/externals/viem/createViemInstance.js.map +1 -1
  23. package/_esm/decoder/tests.js +3 -0
  24. package/_esm/decoder/tests.js.map +1 -1
  25. package/_esm/explorers/definitions/blockscout.js +23 -1
  26. package/_esm/explorers/definitions/blockscout.js.map +1 -1
  27. package/_esm/explorers/definitions/etherscan.js +24 -1
  28. package/_esm/explorers/definitions/etherscan.js.map +1 -1
  29. package/_esm/explorers/definitions/roninExplorer.js +6 -0
  30. package/_esm/explorers/definitions/roninExplorer.js.map +1 -1
  31. package/_esm/explorers/definitions/routescan.js +5 -0
  32. package/_esm/explorers/definitions/routescan.js.map +1 -1
  33. package/_esm/explorers/externals/blockscout/getEventLogsByAddressAndTopics.js +73 -0
  34. package/_esm/explorers/externals/blockscout/getEventLogsByAddressAndTopics.js.map +1 -0
  35. package/_esm/explorers/externals/blockscout/index.js +1 -0
  36. package/_esm/explorers/externals/blockscout/index.js.map +1 -1
  37. package/_esm/explorers/externals/etherscan/getEventLogsByAddressAndTopics.js +74 -0
  38. package/_esm/explorers/externals/etherscan/getEventLogsByAddressAndTopics.js.map +1 -0
  39. package/_esm/explorers/externals/etherscan/index.js +1 -0
  40. package/_esm/explorers/externals/etherscan/index.js.map +1 -1
  41. package/_types/clients/externals/viem/createViemInstance.d.ts.map +1 -1
  42. package/_types/decoder/tests.d.ts.map +1 -1
  43. package/_types/explorers/definitions/blockscout.d.ts +13 -1
  44. package/_types/explorers/definitions/blockscout.d.ts.map +1 -1
  45. package/_types/explorers/definitions/etherscan.d.ts +13 -1
  46. package/_types/explorers/definitions/etherscan.d.ts.map +1 -1
  47. package/_types/explorers/definitions/roninExplorer.d.ts +7 -0
  48. package/_types/explorers/definitions/roninExplorer.d.ts.map +1 -1
  49. package/_types/explorers/definitions/routescan.d.ts +1 -0
  50. package/_types/explorers/definitions/routescan.d.ts.map +1 -1
  51. package/_types/explorers/externals/blockscout/getEventLogsByAddressAndTopics.d.ts +39 -0
  52. package/_types/explorers/externals/blockscout/getEventLogsByAddressAndTopics.d.ts.map +1 -0
  53. package/_types/explorers/externals/blockscout/index.d.ts +1 -0
  54. package/_types/explorers/externals/blockscout/index.d.ts.map +1 -1
  55. package/_types/explorers/externals/etherscan/getEventLogsByAddressAndTopics.d.ts +41 -0
  56. package/_types/explorers/externals/etherscan/getEventLogsByAddressAndTopics.d.ts.map +1 -0
  57. package/_types/explorers/externals/etherscan/index.d.ts +1 -0
  58. package/_types/explorers/externals/etherscan/index.d.ts.map +1 -1
  59. package/_types/explorers/types.d.ts +13 -0
  60. package/_types/explorers/types.d.ts.map +1 -1
  61. package/clients/externals/viem/createViemInstance.ts +4 -2
  62. package/decoder/tests.ts +3 -0
  63. package/explorers/definitions/blockscout.ts +32 -1
  64. package/explorers/definitions/etherscan.ts +30 -1
  65. package/explorers/definitions/roninExplorer.ts +6 -0
  66. package/explorers/definitions/routescan.ts +5 -0
  67. package/explorers/externals/blockscout/getEventLogsByAddressAndTopics.ts +105 -0
  68. package/explorers/externals/blockscout/index.ts +1 -0
  69. package/explorers/externals/etherscan/getEventLogsByAddressAndTopics.ts +111 -0
  70. package/explorers/externals/etherscan/index.ts +1 -0
  71. package/explorers/types.ts +16 -0
  72. package/package.json +1 -1
@@ -0,0 +1,39 @@
1
+ import type { Logger } from '@0xtorch/core';
2
+ import { z } from 'zod';
3
+ import type { Hex } from '../../../types';
4
+ type GetEventLogsByAddressAndTopicsParameters = {
5
+ readonly apiEndpoint: string;
6
+ readonly address: Hex;
7
+ readonly topic0: Hex;
8
+ readonly fromBlock: bigint | 'latest';
9
+ readonly toBlock: bigint | 'latest';
10
+ readonly logger?: Logger;
11
+ };
12
+ declare const logSchema: z.ZodObject<{
13
+ address: z.ZodEffects<z.ZodString, `0x${Lowercase<string>}`, string>;
14
+ topics: z.ZodEffects<z.ZodArray<z.ZodNullable<z.ZodEffects<z.ZodString, `0x${string}`, string>>, "many">, `0x${string}`[], (string | null)[]>;
15
+ data: z.ZodEffects<z.ZodString, `0x${string}`, string>;
16
+ blockNumber: z.ZodEffects<z.ZodString, bigint, string>;
17
+ logIndex: z.ZodEffects<z.ZodString, bigint, string>;
18
+ transactionHash: z.ZodEffects<z.ZodString, `0x${string}`, string>;
19
+ }, "strip", z.ZodTypeAny, {
20
+ address: `0x${Lowercase<string>}`;
21
+ transactionHash: `0x${string}`;
22
+ blockNumber: bigint;
23
+ data: `0x${string}`;
24
+ logIndex: bigint;
25
+ topics: `0x${string}`[];
26
+ }, {
27
+ address: string;
28
+ transactionHash: string;
29
+ blockNumber: string;
30
+ data: string;
31
+ logIndex: string;
32
+ topics: (string | null)[];
33
+ }>;
34
+ type Log = Readonly<z.infer<typeof logSchema>>;
35
+ type ReturnType = readonly Log[];
36
+ /** {@link https://docs.blockscout.com/developer-support/api/rpc-endpoints/logs#get-event-logs-by-address-and-or-topic-s} */
37
+ export declare const getEventLogsByAddressAndTopics: ({ apiEndpoint, address, topic0, fromBlock, toBlock, logger, }: GetEventLogsByAddressAndTopicsParameters) => Promise<ReturnType>;
38
+ export {};
39
+ //# sourceMappingURL=getEventLogsByAddressAndTopics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getEventLogsByAddressAndTopics.d.ts","sourceRoot":"","sources":["../../../../explorers/externals/blockscout/getEventLogsByAddressAndTopics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAIzC,KAAK,wCAAwC,GAAG;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAA;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAA;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAA;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;EA8Bb,CAAA;AAQF,KAAK,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC,CAAA;AAC9C,KAAK,UAAU,GAAG,SAAS,GAAG,EAAE,CAAA;AAEhC,4HAA4H;AAC5H,eAAO,MAAM,8BAA8B,kEAOxC,wCAAwC,KAAG,QAAQ,UAAU,CAwC/D,CAAA"}
@@ -1,6 +1,7 @@
1
1
  export { getBlockNumberOfTimestamp } from './getBlockNumberOfTimestamp';
2
2
  export { getContractByAddress } from './getContractByAddress';
3
3
  export { getContractCreations } from './getContractCreations';
4
+ export { getEventLogsByAddressAndTopics } from './getEventLogsByAddressAndTopics';
4
5
  export { getInternalTransactionsByAddress } from './getInternalTransactionsByAddress';
5
6
  export { getInternalTransactionsByTransactionHash } from './getInternalTransactionsByTransactionHash';
6
7
  export { getNormalTransactionsByAddress } from './getNormalTransactionsByAddress';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../explorers/externals/blockscout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAA;AACrG,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../explorers/externals/blockscout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AACjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAA;AACrG,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA"}
@@ -0,0 +1,41 @@
1
+ import type { Logger } from '@0xtorch/core';
2
+ import { z } from 'zod';
3
+ import type { Hex } from '../../../types';
4
+ type GetEventLogsByAddressAndTopicsParameters = {
5
+ readonly apiEndpoint: string;
6
+ readonly apiKey: string;
7
+ readonly address: Hex;
8
+ readonly topic0: Hex;
9
+ readonly fromBlock?: bigint;
10
+ readonly toBlock?: bigint;
11
+ readonly page?: number;
12
+ readonly logger?: Logger;
13
+ };
14
+ declare const logSchema: z.ZodObject<{
15
+ address: z.ZodEffects<z.ZodString, `0x${Lowercase<string>}`, string>;
16
+ topics: z.ZodArray<z.ZodEffects<z.ZodString, `0x${string}`, string>, "many">;
17
+ data: z.ZodEffects<z.ZodString, `0x${string}`, string>;
18
+ blockNumber: z.ZodEffects<z.ZodString, bigint, string>;
19
+ logIndex: z.ZodEffects<z.ZodString, bigint, string>;
20
+ transactionHash: z.ZodEffects<z.ZodString, `0x${string}`, string>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ address: `0x${Lowercase<string>}`;
23
+ transactionHash: `0x${string}`;
24
+ blockNumber: bigint;
25
+ data: `0x${string}`;
26
+ logIndex: bigint;
27
+ topics: `0x${string}`[];
28
+ }, {
29
+ address: string;
30
+ transactionHash: string;
31
+ blockNumber: string;
32
+ data: string;
33
+ logIndex: string;
34
+ topics: string[];
35
+ }>;
36
+ type Log = Readonly<z.infer<typeof logSchema>>;
37
+ type ReturnType = readonly Log[];
38
+ /** {@link https://docs.etherscan.io/api-endpoints/logs#get-event-logs-by-address-filtered-by-topics} */
39
+ export declare const getEventLogsByAddressAndTopics: ({ apiEndpoint, apiKey, address, topic0, fromBlock, toBlock, page, logger, }: GetEventLogsByAddressAndTopicsParameters) => Promise<ReturnType>;
40
+ export {};
41
+ //# sourceMappingURL=getEventLogsByAddressAndTopics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getEventLogsByAddressAndTopics.d.ts","sourceRoot":"","sources":["../../../../explorers/externals/etherscan/getEventLogsByAddressAndTopics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAIzC,KAAK,wCAAwC,GAAG;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAA;IACpB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;EA2Bb,CAAA;AAQF,KAAK,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC,CAAA;AAC9C,KAAK,UAAU,GAAG,SAAS,GAAG,EAAE,CAAA;AAEhC,wGAAwG;AACxG,eAAO,MAAM,8BAA8B,gFASxC,wCAAwC,KAAG,QAAQ,UAAU,CA6C/D,CAAA"}
@@ -4,6 +4,7 @@ export { getContractCreations } from './getContractCreations';
4
4
  export { getErc1155TokenTransfersByAddress } from './getErc1155TokenTransfersByAddress';
5
5
  export { getErc20TokenTransfersByAddress } from './getErc20TokenTransfersByAddress';
6
6
  export { getErc721TokenTransfersByAddress } from './getErc721TokenTransfersByAddress';
7
+ export { getEventLogsByAddressAndTopics } from './getEventLogsByAddressAndTopics';
7
8
  export { getInternalTransactionsByAddress } from './getInternalTransactionsByAddress';
8
9
  export { getInternalTransactionsByTransactionHash } from './getInternalTransactionsByTransactionHash';
9
10
  export { getNormalTransactionsByAddress } from './getNormalTransactionsByAddress';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../explorers/externals/etherscan/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAA;AACvF,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAA;AACnF,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAA;AACrG,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../explorers/externals/etherscan/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAA;AACvF,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAA;AACnF,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AACjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAA;AACrG,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA"}
@@ -13,6 +13,7 @@ export type Explorer = {
13
13
  readonly getBlockNumberOfTimestamp: (timestamp: number, logger?: Logger) => Promise<bigint>;
14
14
  readonly getContract: FunctionGetContract;
15
15
  readonly getContractCreations: FunctionGetContractCreations;
16
+ readonly getEventLogs: FunctionGetEventLogs;
16
17
  readonly getInternalTransactionOfTransaction: FunctionGetInternalTransactionOfTransaction;
17
18
  };
18
19
  type FunctionGetAddressTransactionHashes = (parameters: {
@@ -70,6 +71,18 @@ type FunctionGetContractCreations = (addresses: readonly Hex[], logger?: Logger)
70
71
  readonly contractCreator: LowerHex | undefined;
71
72
  readonly txHash: Hex | undefined;
72
73
  }[]>;
74
+ type FunctionGetEventLogs = (parameters: {
75
+ readonly address: Hex;
76
+ readonly topic0: Hex;
77
+ readonly fromBlock?: bigint;
78
+ readonly toBlock?: bigint;
79
+ readonly logger?: Logger;
80
+ }) => Promise<readonly {
81
+ blockNumber: bigint;
82
+ transactionHash: Hex;
83
+ data: Hex;
84
+ topics: readonly Hex[];
85
+ }[]>;
73
86
  type FunctionGetInternalTransactionOfTransaction = (parameters: {
74
87
  readonly hash: Hex;
75
88
  readonly nativeCurrency: CryptoCurrency;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../explorers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAElE,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,Q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CAAA;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB,KAAK,OAAO,CACX,SAAS;IACP,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,GAAG,CAAA;IACpB,IAAI,EAAE,GAAG,CAAA;IACT,MAAM,EAAE,SAAS,GAAG,EAAE,CAAA;CACvB,EAAE,CACJ,CAAA;AAED,KAAK,2CAA2C,GAAG,CAAC,UAAU,EAAE;IAC9D,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAA;IAClB,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAA;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB,KAAK,OAAO,CAAC,SAAS,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA"}
@@ -81,12 +81,14 @@ export const createViemInstance = (() => {
81
81
  })
82
82
  return await caller(client)
83
83
  } catch (error) {
84
- // TODO 後で消す
85
- console.debug(error)
86
84
  if (error instanceof HttpRequestError && error.status === 429) {
85
+ // TODO 後で消す
86
+ console.debug(error)
87
87
  cooldownEndpoint(endpoint)
88
88
  return await call(chain, caller, timeout - (Date.now() - start))
89
89
  } else if (error instanceof TransactionReceiptNotFoundError) {
90
+ // TODO 後で消す
91
+ console.debug(error)
90
92
  cooldownEndpoint(endpoint, 5000)
91
93
  return await call(chain, caller, timeout - (Date.now() - start))
92
94
  }
package/decoder/tests.ts CHANGED
@@ -76,6 +76,9 @@ const testExplorer: Explorer = {
76
76
  getContractCreations: () => {
77
77
  throw new Error('Not implemented')
78
78
  },
79
+ getEventLogs: () => {
80
+ throw new Error('Not implemented')
81
+ },
79
82
  getInternalTransactionOfTransaction: () => {
80
83
  throw new Error('Not implemented')
81
84
  },
@@ -1,9 +1,10 @@
1
1
  import type { Logger } from '@0xtorch/core'
2
- import type { InternalTransaction, LowerHex } from '../../types'
2
+ import type { Hex, InternalTransaction, LowerHex } from '../../types'
3
3
  import {
4
4
  getContractCreations as apiGetContractCreations,
5
5
  getBlockNumberOfTimestamp,
6
6
  getContractByAddress,
7
+ getEventLogsByAddressAndTopics,
7
8
  getInternalTransactionsByAddress,
8
9
  getInternalTransactionsByTransactionHash,
9
10
  getNormalTransactionsByAddress,
@@ -190,6 +191,36 @@ export const createBlockscout = <
190
191
  })
191
192
  return creations
192
193
  },
194
+ getEventLogs: async ({ address, topic0, fromBlock, toBlock, logger }) => {
195
+ const loop = true
196
+ let mut_fromBlock = fromBlock ?? 0n
197
+ const mut_logs: {
198
+ blockNumber: bigint
199
+ transactionHash: Hex
200
+ data: Hex
201
+ topics: readonly Hex[]
202
+ }[] = []
203
+ while (loop) {
204
+ const logs = await getEventLogsByAddressAndTopics({
205
+ apiEndpoint: apiUrl,
206
+ address,
207
+ topic0,
208
+ fromBlock: mut_fromBlock,
209
+ toBlock: toBlock ?? 'latest',
210
+ logger,
211
+ })
212
+ mut_logs.push(...logs)
213
+ if (logs.length < 1000) {
214
+ break
215
+ }
216
+ const maxBlockNumber = logs.reduce(
217
+ (max, { blockNumber }) => (max < blockNumber ? blockNumber : max),
218
+ logs[0].blockNumber,
219
+ )
220
+ mut_fromBlock = maxBlockNumber
221
+ }
222
+ return mut_logs
223
+ },
193
224
  getInternalTransactionOfTransaction: async ({
194
225
  hash,
195
226
  nativeCurrency,
@@ -1,5 +1,5 @@
1
1
  import type { Logger } from '@0xtorch/core'
2
- import type { InternalTransaction, LowerHex } from '../../types'
2
+ import type { Hex, InternalTransaction, LowerHex } from '../../types'
3
3
  import {
4
4
  getContractCreations as apiGetContractCreations,
5
5
  getBlockNumberOfTimestamp,
@@ -7,6 +7,7 @@ import {
7
7
  getErc1155TokenTransfersByAddress,
8
8
  getErc20TokenTransfersByAddress,
9
9
  getErc721TokenTransfersByAddress,
10
+ getEventLogsByAddressAndTopics,
10
11
  getInternalTransactionsByAddress,
11
12
  getInternalTransactionsByTransactionHash,
12
13
  getNormalTransactionsByAddress,
@@ -268,6 +269,34 @@ export const createEtherscan = <
268
269
  txHash: creation.txHash,
269
270
  }))
270
271
  },
272
+ getEventLogs: async ({ address, topic0, fromBlock, toBlock, logger }) => {
273
+ const loop = true
274
+ let mut_page: number | undefined
275
+ const mut_logs: {
276
+ blockNumber: bigint
277
+ transactionHash: Hex
278
+ data: Hex
279
+ topics: readonly Hex[]
280
+ }[] = []
281
+ while (loop) {
282
+ const logs = await getEventLogsByAddressAndTopics({
283
+ apiEndpoint: apiUrl,
284
+ apiKey,
285
+ address,
286
+ topic0,
287
+ fromBlock,
288
+ toBlock,
289
+ page: mut_page,
290
+ logger,
291
+ })
292
+ mut_logs.push(...logs)
293
+ if (logs.length < 1000) {
294
+ break
295
+ }
296
+ mut_page = (mut_page ?? 0) + 1
297
+ }
298
+ return mut_logs
299
+ },
271
300
  getInternalTransactionOfTransaction: async ({
272
301
  hash,
273
302
  nativeCurrency,
@@ -130,6 +130,12 @@ export const createRoninExplorer = <
130
130
  }
131
131
  throw new Error('Not supported')
132
132
  },
133
+ getEventLogs: ({ logger }) => {
134
+ if (logger !== undefined) {
135
+ logger.info('getEventLogs is not supported on Ronin Explorer')
136
+ }
137
+ throw new Error('Not supported')
138
+ },
133
139
  getInternalTransactionOfTransaction: async ({
134
140
  hash,
135
141
  nativeCurrency,
@@ -54,6 +54,11 @@ export const createRoutescan = <
54
54
  await new Promise((resolve) => setTimeout(resolve))
55
55
  throw new Error('not implemented')
56
56
  },
57
+ getEventLogs: async () => {
58
+ // TODO implement
59
+ await new Promise((resolve) => setTimeout(resolve))
60
+ throw new Error('not implemented')
61
+ },
57
62
  getInternalTransactionOfTransaction: async () => {
58
63
  // TODO implement
59
64
  await new Promise((resolve) => setTimeout(resolve))
@@ -0,0 +1,105 @@
1
+ import type { Logger } from '@0xtorch/core'
2
+ import { z } from 'zod'
3
+ import type { Hex } from '../../../types'
4
+ import { isHex, toLowerHex } from '../../../types'
5
+ import { createBlockscoutClient } from './middleware'
6
+
7
+ type GetEventLogsByAddressAndTopicsParameters = {
8
+ readonly apiEndpoint: string
9
+ readonly address: Hex
10
+ readonly topic0: Hex
11
+ readonly fromBlock: bigint | 'latest'
12
+ readonly toBlock: bigint | 'latest'
13
+ readonly logger?: Logger
14
+ }
15
+
16
+ const logSchema = z.object({
17
+ address: z
18
+ .string()
19
+ .regex(/^0x[\da-f]{40}$/)
20
+ .transform((x) => (isHex(x) ? toLowerHex(x) : '0x')),
21
+ topics: z
22
+ .array(
23
+ z
24
+ .string()
25
+ .regex(/^0x[\da-f]{64}$/)
26
+ .transform((x) => (isHex(x) ? x : '0x'))
27
+ .nullable(),
28
+ )
29
+ .transform((x) => x.filter((y): y is Hex => y !== null)),
30
+ data: z
31
+ .string()
32
+ .regex(/^0x[\da-f]*$/)
33
+ .transform((x) => (isHex(x) ? x : '0x')),
34
+ blockNumber: z
35
+ .string()
36
+ .regex(/^0x[\da-f]*$/)
37
+ .transform(BigInt),
38
+ logIndex: z
39
+ .string()
40
+ .regex(/^0x[\da-f]*$/)
41
+ .transform(BigInt),
42
+ transactionHash: z
43
+ .string()
44
+ .regex(/^0x[\da-f]{64}$/)
45
+ .transform((x) => (isHex(x) ? x : '0x')),
46
+ })
47
+
48
+ const responseSchema = z.object({
49
+ status: z.string(),
50
+ message: z.string(),
51
+ result: z.union([z.array(logSchema), z.string()]).nullable(),
52
+ })
53
+
54
+ type Log = Readonly<z.infer<typeof logSchema>>
55
+ type ReturnType = readonly Log[]
56
+
57
+ /** {@link https://docs.blockscout.com/developer-support/api/rpc-endpoints/logs#get-event-logs-by-address-and-or-topic-s} */
58
+ export const getEventLogsByAddressAndTopics = async ({
59
+ apiEndpoint,
60
+ address,
61
+ topic0,
62
+ fromBlock,
63
+ toBlock,
64
+ logger,
65
+ }: GetEventLogsByAddressAndTopicsParameters): Promise<ReturnType> => {
66
+ try {
67
+ const { status, message, result } = await createBlockscoutClient(
68
+ apiEndpoint,
69
+ ).get(
70
+ '',
71
+ {
72
+ module: 'logs',
73
+ action: 'getLogs',
74
+ address,
75
+ topic0,
76
+ fromBlock: fromBlock.toString(),
77
+ toBlock: toBlock.toString(),
78
+ },
79
+ responseSchema,
80
+ logger,
81
+ )
82
+ if (status !== '1' || result === null) {
83
+ const error =
84
+ typeof result === 'string' ? new Error(result) : new Error(message)
85
+ throw error
86
+ }
87
+ if (typeof result === 'string') {
88
+ throw new TypeError(result)
89
+ }
90
+ return result
91
+ } catch (error) {
92
+ if (error instanceof Error && error.message === 'Max rate limit reached') {
93
+ await new Promise((resolve) => setTimeout(resolve, 1000))
94
+ return await getEventLogsByAddressAndTopics({
95
+ apiEndpoint,
96
+ address,
97
+ topic0,
98
+ fromBlock,
99
+ toBlock,
100
+ logger,
101
+ })
102
+ }
103
+ throw error
104
+ }
105
+ }
@@ -1,6 +1,7 @@
1
1
  export { getBlockNumberOfTimestamp } from './getBlockNumberOfTimestamp'
2
2
  export { getContractByAddress } from './getContractByAddress'
3
3
  export { getContractCreations } from './getContractCreations'
4
+ export { getEventLogsByAddressAndTopics } from './getEventLogsByAddressAndTopics'
4
5
  export { getInternalTransactionsByAddress } from './getInternalTransactionsByAddress'
5
6
  export { getInternalTransactionsByTransactionHash } from './getInternalTransactionsByTransactionHash'
6
7
  export { getNormalTransactionsByAddress } from './getNormalTransactionsByAddress'
@@ -0,0 +1,111 @@
1
+ import type { Logger } from '@0xtorch/core'
2
+ import { z } from 'zod'
3
+ import type { Hex } from '../../../types'
4
+ import { isHex, toLowerHex } from '../../../types'
5
+ import { createEtherscanClient } from './middleware'
6
+
7
+ type GetEventLogsByAddressAndTopicsParameters = {
8
+ readonly apiEndpoint: string
9
+ readonly apiKey: string
10
+ readonly address: Hex
11
+ readonly topic0: Hex
12
+ readonly fromBlock?: bigint
13
+ readonly toBlock?: bigint
14
+ readonly page?: number
15
+ readonly logger?: Logger
16
+ }
17
+
18
+ const logSchema = z.object({
19
+ address: z
20
+ .string()
21
+ .regex(/^0x[\da-f]{40}$/)
22
+ .transform((x) => (isHex(x) ? toLowerHex(x) : '0x')),
23
+ topics: z.array(
24
+ z
25
+ .string()
26
+ .regex(/^0x[\da-f]{64}$/)
27
+ .transform((x) => (isHex(x) ? x : '0x')),
28
+ ),
29
+ data: z
30
+ .string()
31
+ .regex(/^0x[\da-f]*$/)
32
+ .transform((x) => (isHex(x) ? x : '0x')),
33
+ blockNumber: z
34
+ .string()
35
+ .regex(/^0x[\da-f]*$/)
36
+ .transform(BigInt),
37
+ logIndex: z
38
+ .string()
39
+ .regex(/^0x[\da-f]*$/)
40
+ .transform(BigInt),
41
+ transactionHash: z
42
+ .string()
43
+ .regex(/^0x[\da-f]{64}$/)
44
+ .transform((x) => (isHex(x) ? x : '0x')),
45
+ })
46
+
47
+ const responseSchema = z.object({
48
+ status: z.string(),
49
+ message: z.string(),
50
+ result: z.union([z.array(logSchema), z.string()]).nullable(),
51
+ })
52
+
53
+ type Log = Readonly<z.infer<typeof logSchema>>
54
+ type ReturnType = readonly Log[]
55
+
56
+ /** {@link https://docs.etherscan.io/api-endpoints/logs#get-event-logs-by-address-filtered-by-topics} */
57
+ export const getEventLogsByAddressAndTopics = async ({
58
+ apiEndpoint,
59
+ apiKey,
60
+ address,
61
+ topic0,
62
+ fromBlock,
63
+ toBlock,
64
+ page,
65
+ logger,
66
+ }: GetEventLogsByAddressAndTopicsParameters): Promise<ReturnType> => {
67
+ try {
68
+ const { status, message, result } = await createEtherscanClient(
69
+ apiEndpoint,
70
+ apiKey,
71
+ ).get(
72
+ '',
73
+ {
74
+ module: 'logs',
75
+ action: 'getLogs',
76
+ address,
77
+ topic0,
78
+ ...(fromBlock === undefined ? {} : { fromBlock: fromBlock.toString() }),
79
+ ...(toBlock === undefined ? {} : { toBlock: toBlock.toString() }),
80
+ ...(page === undefined ? {} : { page: page.toString() }),
81
+ offset: '1000',
82
+ },
83
+ responseSchema,
84
+ logger,
85
+ )
86
+ if (status !== '1' || result === null) {
87
+ const error =
88
+ typeof result === 'string' ? new Error(result) : new Error(message)
89
+ throw error
90
+ }
91
+ if (typeof result === 'string') {
92
+ throw new TypeError(result)
93
+ }
94
+ return result
95
+ } catch (error) {
96
+ if (error instanceof Error && error.message === 'Max rate limit reached') {
97
+ await new Promise((resolve) => setTimeout(resolve, 1000))
98
+ return await getEventLogsByAddressAndTopics({
99
+ apiEndpoint,
100
+ apiKey,
101
+ address,
102
+ topic0,
103
+ fromBlock,
104
+ toBlock,
105
+ page,
106
+ logger,
107
+ })
108
+ }
109
+ throw error
110
+ }
111
+ }
@@ -4,6 +4,7 @@ export { getContractCreations } from './getContractCreations'
4
4
  export { getErc1155TokenTransfersByAddress } from './getErc1155TokenTransfersByAddress'
5
5
  export { getErc20TokenTransfersByAddress } from './getErc20TokenTransfersByAddress'
6
6
  export { getErc721TokenTransfersByAddress } from './getErc721TokenTransfersByAddress'
7
+ export { getEventLogsByAddressAndTopics } from './getEventLogsByAddressAndTopics'
7
8
  export { getInternalTransactionsByAddress } from './getInternalTransactionsByAddress'
8
9
  export { getInternalTransactionsByTransactionHash } from './getInternalTransactionsByTransactionHash'
9
10
  export { getNormalTransactionsByAddress } from './getNormalTransactionsByAddress'
@@ -17,6 +17,7 @@ export type Explorer = {
17
17
  ) => Promise<bigint>
18
18
  readonly getContract: FunctionGetContract
19
19
  readonly getContractCreations: FunctionGetContractCreations
20
+ readonly getEventLogs: FunctionGetEventLogs
20
21
  readonly getInternalTransactionOfTransaction: FunctionGetInternalTransactionOfTransaction
21
22
  }
22
23
 
@@ -98,6 +99,21 @@ type FunctionGetContractCreations = (
98
99
  }[]
99
100
  >
100
101
 
102
+ type FunctionGetEventLogs = (parameters: {
103
+ readonly address: Hex
104
+ readonly topic0: Hex
105
+ readonly fromBlock?: bigint
106
+ readonly toBlock?: bigint
107
+ readonly logger?: Logger
108
+ }) => Promise<
109
+ readonly {
110
+ blockNumber: bigint
111
+ transactionHash: Hex
112
+ data: Hex
113
+ topics: readonly Hex[]
114
+ }[]
115
+ >
116
+
101
117
  type FunctionGetInternalTransactionOfTransaction = (parameters: {
102
118
  readonly hash: Hex
103
119
  readonly nativeCurrency: CryptoCurrency
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xtorch/evm",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "description": "Cryptorch EVM extension",
5
5
  "keywords": [
6
6
  "cryptorch",