@0xtorch/evm 0.0.51 → 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.
- package/_cjs/clients/externals/viem/createViemInstance.js +2 -1
- package/_cjs/clients/externals/viem/createViemInstance.js.map +1 -1
- package/_cjs/decoder/tests.js +3 -0
- package/_cjs/decoder/tests.js.map +1 -1
- package/_cjs/explorers/definitions/blockscout.js +22 -0
- package/_cjs/explorers/definitions/blockscout.js.map +1 -1
- package/_cjs/explorers/definitions/etherscan.js +28 -1
- package/_cjs/explorers/definitions/etherscan.js.map +1 -1
- package/_cjs/explorers/definitions/roninExplorer.js +6 -0
- package/_cjs/explorers/definitions/roninExplorer.js.map +1 -1
- package/_cjs/explorers/definitions/routescan.js +4 -0
- package/_cjs/explorers/definitions/routescan.js.map +1 -1
- package/_cjs/explorers/externals/blockscout/getEventLogsByAddressAndTopics.js +76 -0
- package/_cjs/explorers/externals/blockscout/getEventLogsByAddressAndTopics.js.map +1 -0
- package/_cjs/explorers/externals/blockscout/index.js +3 -1
- package/_cjs/explorers/externals/blockscout/index.js.map +1 -1
- package/_cjs/explorers/externals/etherscan/getContractCreations.js +14 -8
- package/_cjs/explorers/externals/etherscan/getContractCreations.js.map +1 -1
- package/_cjs/explorers/externals/etherscan/getEventLogsByAddressAndTopics.js +77 -0
- package/_cjs/explorers/externals/etherscan/getEventLogsByAddressAndTopics.js.map +1 -0
- package/_cjs/explorers/externals/etherscan/index.js +3 -1
- package/_cjs/explorers/externals/etherscan/index.js.map +1 -1
- package/_esm/clients/externals/viem/createViemInstance.js +4 -2
- package/_esm/clients/externals/viem/createViemInstance.js.map +1 -1
- package/_esm/decoder/tests.js +3 -0
- package/_esm/decoder/tests.js.map +1 -1
- package/_esm/explorers/definitions/blockscout.js +23 -1
- package/_esm/explorers/definitions/blockscout.js.map +1 -1
- package/_esm/explorers/definitions/etherscan.js +29 -2
- package/_esm/explorers/definitions/etherscan.js.map +1 -1
- package/_esm/explorers/definitions/roninExplorer.js +6 -0
- package/_esm/explorers/definitions/roninExplorer.js.map +1 -1
- package/_esm/explorers/definitions/routescan.js +5 -0
- package/_esm/explorers/definitions/routescan.js.map +1 -1
- package/_esm/explorers/externals/blockscout/getEventLogsByAddressAndTopics.js +73 -0
- package/_esm/explorers/externals/blockscout/getEventLogsByAddressAndTopics.js.map +1 -0
- package/_esm/explorers/externals/blockscout/index.js +1 -0
- package/_esm/explorers/externals/blockscout/index.js.map +1 -1
- package/_esm/explorers/externals/etherscan/getContractCreations.js +14 -8
- package/_esm/explorers/externals/etherscan/getContractCreations.js.map +1 -1
- package/_esm/explorers/externals/etherscan/getEventLogsByAddressAndTopics.js +74 -0
- package/_esm/explorers/externals/etherscan/getEventLogsByAddressAndTopics.js.map +1 -0
- package/_esm/explorers/externals/etherscan/index.js +1 -0
- package/_esm/explorers/externals/etherscan/index.js.map +1 -1
- package/_types/clients/externals/viem/createViemInstance.d.ts.map +1 -1
- package/_types/decoder/tests.d.ts.map +1 -1
- package/_types/explorers/definitions/blockscout.d.ts +13 -1
- package/_types/explorers/definitions/blockscout.d.ts.map +1 -1
- package/_types/explorers/definitions/etherscan.d.ts +17 -5
- package/_types/explorers/definitions/etherscan.d.ts.map +1 -1
- package/_types/explorers/definitions/roninExplorer.d.ts +7 -0
- package/_types/explorers/definitions/roninExplorer.d.ts.map +1 -1
- package/_types/explorers/definitions/routescan.d.ts +1 -0
- package/_types/explorers/definitions/routescan.d.ts.map +1 -1
- package/_types/explorers/externals/blockscout/getEventLogsByAddressAndTopics.d.ts +39 -0
- package/_types/explorers/externals/blockscout/getEventLogsByAddressAndTopics.d.ts.map +1 -0
- package/_types/explorers/externals/blockscout/index.d.ts +1 -0
- package/_types/explorers/externals/blockscout/index.d.ts.map +1 -1
- package/_types/explorers/externals/etherscan/getContractCreations.d.ts +4 -4
- package/_types/explorers/externals/etherscan/getContractCreations.d.ts.map +1 -1
- package/_types/explorers/externals/etherscan/getEventLogsByAddressAndTopics.d.ts +41 -0
- package/_types/explorers/externals/etherscan/getEventLogsByAddressAndTopics.d.ts.map +1 -0
- package/_types/explorers/externals/etherscan/index.d.ts +1 -0
- package/_types/explorers/externals/etherscan/index.d.ts.map +1 -1
- package/_types/explorers/types.d.ts +17 -4
- package/_types/explorers/types.d.ts.map +1 -1
- package/clients/externals/viem/createViemInstance.ts +4 -2
- package/decoder/tests.ts +3 -0
- package/explorers/definitions/blockscout.ts +32 -1
- package/explorers/definitions/etherscan.ts +35 -2
- package/explorers/definitions/roninExplorer.ts +6 -0
- package/explorers/definitions/routescan.ts +5 -0
- package/explorers/externals/blockscout/getEventLogsByAddressAndTopics.ts +105 -0
- package/explorers/externals/blockscout/index.ts +1 -0
- package/explorers/externals/etherscan/getContractCreations.ts +14 -8
- package/explorers/externals/etherscan/getEventLogsByAddressAndTopics.ts +111 -0
- package/explorers/externals/etherscan/index.ts +1 -0
- package/explorers/types.ts +20 -4
- package/package.json +1 -1
|
@@ -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'
|
package/explorers/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CryptoCurrency, Logger } from '@0xtorch/core'
|
|
2
|
-
import type { Hex, InternalTransaction } from '../types'
|
|
2
|
+
import type { Hex, InternalTransaction, LowerHex } from '../types'
|
|
3
3
|
|
|
4
4
|
export type Explorer = {
|
|
5
5
|
readonly name: string
|
|
@@ -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
|
|
|
@@ -92,9 +93,24 @@ type FunctionGetContractCreations = (
|
|
|
92
93
|
logger?: Logger,
|
|
93
94
|
) => Promise<
|
|
94
95
|
readonly {
|
|
95
|
-
readonly contractAddress:
|
|
96
|
-
readonly contractCreator:
|
|
97
|
-
readonly txHash: Hex
|
|
96
|
+
readonly contractAddress: LowerHex
|
|
97
|
+
readonly contractCreator: LowerHex | undefined
|
|
98
|
+
readonly txHash: Hex | undefined
|
|
99
|
+
}[]
|
|
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[]
|
|
98
114
|
}[]
|
|
99
115
|
>
|
|
100
116
|
|