@0xtorch/evm 0.0.46 → 0.0.47
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/decoder/tests.js +3 -0
- package/_cjs/decoder/tests.js.map +1 -1
- package/_cjs/explorers/definitions/blockscout.js +8 -0
- package/_cjs/explorers/definitions/blockscout.js.map +1 -1
- package/_cjs/explorers/definitions/etherscan.js +9 -0
- 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/getContractCreations.js +64 -0
- package/_cjs/explorers/externals/blockscout/getContractCreations.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 +56 -0
- package/_cjs/explorers/externals/etherscan/getContractCreations.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/decoder/tests.js +3 -0
- package/_esm/decoder/tests.js.map +1 -1
- package/_esm/explorers/definitions/blockscout.js +9 -1
- package/_esm/explorers/definitions/blockscout.js.map +1 -1
- package/_esm/explorers/definitions/etherscan.js +10 -1
- 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/getContractCreations.js +61 -0
- package/_esm/explorers/externals/blockscout/getContractCreations.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 +53 -0
- package/_esm/explorers/externals/etherscan/getContractCreations.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/decoder/tests.d.ts.map +1 -1
- package/_types/explorers/definitions/blockscout.d.ts +5 -0
- package/_types/explorers/definitions/blockscout.d.ts.map +1 -1
- package/_types/explorers/definitions/etherscan.d.ts +5 -0
- package/_types/explorers/definitions/etherscan.d.ts.map +1 -1
- package/_types/explorers/definitions/roninExplorer.d.ts +10 -8
- 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/getContractCreations.d.ts +27 -0
- package/_types/explorers/externals/blockscout/getContractCreations.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 +28 -0
- package/_types/explorers/externals/etherscan/getContractCreations.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 +6 -0
- package/_types/explorers/types.d.ts.map +1 -1
- package/decoder/tests.ts +3 -0
- package/explorers/definitions/blockscout.ts +9 -0
- package/explorers/definitions/etherscan.ts +10 -0
- package/explorers/definitions/roninExplorer.ts +7 -0
- package/explorers/definitions/routescan.ts +5 -0
- package/explorers/externals/blockscout/getContractCreations.ts +85 -0
- package/explorers/externals/blockscout/index.ts +1 -0
- package/explorers/externals/etherscan/getContractCreations.ts +80 -0
- package/explorers/externals/etherscan/index.ts +1 -0
- package/explorers/types.ts +12 -0
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Logger } from '@0xtorch/core'
|
|
1
2
|
import type { Hex } from 'viem'
|
|
2
3
|
import type { LowerHex } from '../../types'
|
|
3
4
|
import {
|
|
@@ -123,6 +124,12 @@ export const createRoninExplorer = <
|
|
|
123
124
|
}
|
|
124
125
|
return Promise.resolve(undefined)
|
|
125
126
|
},
|
|
127
|
+
getContractCreations: (_, logger?: Logger) => {
|
|
128
|
+
if (logger !== undefined) {
|
|
129
|
+
logger.info('getContractCreations is not supported on Ronin Explorer')
|
|
130
|
+
}
|
|
131
|
+
throw new Error('Not supported')
|
|
132
|
+
},
|
|
126
133
|
getInternalTransactionOfTransaction: async ({
|
|
127
134
|
hash,
|
|
128
135
|
nativeCurrency,
|
|
@@ -49,6 +49,11 @@ export const createRoutescan = <
|
|
|
49
49
|
await new Promise((resolve) => setTimeout(resolve))
|
|
50
50
|
throw new Error('not implemented')
|
|
51
51
|
},
|
|
52
|
+
getContractCreations: async () => {
|
|
53
|
+
// TODO implement
|
|
54
|
+
await new Promise((resolve) => setTimeout(resolve))
|
|
55
|
+
throw new Error('not implemented')
|
|
56
|
+
},
|
|
52
57
|
getInternalTransactionOfTransaction: async () => {
|
|
53
58
|
// TODO implement
|
|
54
59
|
await new Promise((resolve) => setTimeout(resolve))
|
|
@@ -0,0 +1,85 @@
|
|
|
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 GetContractCreationsParameters = {
|
|
8
|
+
readonly apiEndpoint: string
|
|
9
|
+
readonly addresses: readonly Hex[]
|
|
10
|
+
readonly logger?: Logger
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const contractCreationSchema = z.object({
|
|
14
|
+
contractAddress: z
|
|
15
|
+
.string()
|
|
16
|
+
.regex(/^0x[\da-f]{40}$/)
|
|
17
|
+
.transform((x) => (isHex(x) ? toLowerHex(x) : '0x')),
|
|
18
|
+
contractCreator: z
|
|
19
|
+
.string()
|
|
20
|
+
.regex(/^0x[\da-f]{40}$/)
|
|
21
|
+
.transform((x) => (isHex(x) ? toLowerHex(x) : '0x')),
|
|
22
|
+
txHash: z
|
|
23
|
+
.string()
|
|
24
|
+
.regex(/^0x[\da-f]{64}$/)
|
|
25
|
+
.transform((x) => (isHex(x) ? toLowerHex(x) : '0x')),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const responseSchema = z.object({
|
|
29
|
+
status: z.string(),
|
|
30
|
+
message: z.string(),
|
|
31
|
+
result: z
|
|
32
|
+
.union([
|
|
33
|
+
z.array(contractCreationSchema),
|
|
34
|
+
z.array(z.object({})).transform(() => undefined),
|
|
35
|
+
z.string(),
|
|
36
|
+
])
|
|
37
|
+
.nullable(),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
type ContractCreation = Readonly<z.infer<typeof contractCreationSchema>>
|
|
41
|
+
type ReturnType = readonly ContractCreation[]
|
|
42
|
+
|
|
43
|
+
/** {@link https://docs.blockscout.com/developer-support/api/rpc-endpoints/contract#get-contract-creator-address-hash-and-creation-transaction-hash} */
|
|
44
|
+
export const getContractCreations = async ({
|
|
45
|
+
apiEndpoint,
|
|
46
|
+
addresses,
|
|
47
|
+
logger,
|
|
48
|
+
}: GetContractCreationsParameters): Promise<ReturnType> => {
|
|
49
|
+
try {
|
|
50
|
+
const { status, message, result } = await createBlockscoutClient(
|
|
51
|
+
apiEndpoint,
|
|
52
|
+
).get(
|
|
53
|
+
'',
|
|
54
|
+
{
|
|
55
|
+
module: 'contract',
|
|
56
|
+
action: 'getcontractcreation',
|
|
57
|
+
contractaddresses: addresses.join(','),
|
|
58
|
+
},
|
|
59
|
+
responseSchema,
|
|
60
|
+
logger,
|
|
61
|
+
)
|
|
62
|
+
if (status !== '1' || result === null) {
|
|
63
|
+
const error =
|
|
64
|
+
typeof result === 'string' ? new Error(result) : new Error(message)
|
|
65
|
+
throw error
|
|
66
|
+
}
|
|
67
|
+
if (typeof result === 'string') {
|
|
68
|
+
throw new TypeError(result)
|
|
69
|
+
}
|
|
70
|
+
if (result === undefined) {
|
|
71
|
+
return []
|
|
72
|
+
}
|
|
73
|
+
return result
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof Error && error.message === 'Max rate limit reached') {
|
|
76
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
77
|
+
return await getContractCreations({
|
|
78
|
+
apiEndpoint,
|
|
79
|
+
addresses,
|
|
80
|
+
logger,
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
throw error
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { getBlockNumberOfTimestamp } from './getBlockNumberOfTimestamp'
|
|
2
2
|
export { getContractByAddress } from './getContractByAddress'
|
|
3
|
+
export { getContractCreations } from './getContractCreations'
|
|
3
4
|
export { getInternalTransactionsByAddress } from './getInternalTransactionsByAddress'
|
|
4
5
|
export { getInternalTransactionsByTransactionHash } from './getInternalTransactionsByTransactionHash'
|
|
5
6
|
export { getNormalTransactionsByAddress } from './getNormalTransactionsByAddress'
|
|
@@ -0,0 +1,80 @@
|
|
|
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 GetContractCreationsParameters = {
|
|
8
|
+
readonly apiEndpoint: string
|
|
9
|
+
readonly apiKey: string
|
|
10
|
+
readonly addresses: readonly Hex[]
|
|
11
|
+
readonly logger?: Logger
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const contractCreationSchema = z.object({
|
|
15
|
+
contractAddress: z
|
|
16
|
+
.string()
|
|
17
|
+
.regex(/^0x[\da-f]{40}$/)
|
|
18
|
+
.transform((x) => (isHex(x) ? toLowerHex(x) : '0x')),
|
|
19
|
+
contractCreator: z
|
|
20
|
+
.string()
|
|
21
|
+
.regex(/^0x[\da-f]{40}$/)
|
|
22
|
+
.transform((x) => (isHex(x) ? toLowerHex(x) : '0x')),
|
|
23
|
+
txHash: z
|
|
24
|
+
.string()
|
|
25
|
+
.regex(/^0x[\da-f]{64}$/)
|
|
26
|
+
.transform((x) => (isHex(x) ? toLowerHex(x) : '0x')),
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const responseSchema = z.object({
|
|
30
|
+
status: z.string(),
|
|
31
|
+
message: z.string(),
|
|
32
|
+
result: z.union([z.array(contractCreationSchema), z.string()]).nullable(),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
type ContractCreation = Readonly<z.infer<typeof contractCreationSchema>>
|
|
36
|
+
type ReturnType = readonly ContractCreation[]
|
|
37
|
+
|
|
38
|
+
/** {@link https://docs.etherscan.io/api-endpoints/contracts#get-contract-creator-and-creation-tx-hash} */
|
|
39
|
+
export const getContractCreations = async ({
|
|
40
|
+
apiEndpoint,
|
|
41
|
+
apiKey,
|
|
42
|
+
addresses,
|
|
43
|
+
logger,
|
|
44
|
+
}: GetContractCreationsParameters): Promise<ReturnType> => {
|
|
45
|
+
try {
|
|
46
|
+
const { status, message, result } = await createEtherscanClient(
|
|
47
|
+
apiEndpoint,
|
|
48
|
+
apiKey,
|
|
49
|
+
).get(
|
|
50
|
+
'',
|
|
51
|
+
{
|
|
52
|
+
module: 'contract',
|
|
53
|
+
action: 'getcontractcreation',
|
|
54
|
+
contractaddresses: addresses.join(','),
|
|
55
|
+
},
|
|
56
|
+
responseSchema,
|
|
57
|
+
logger,
|
|
58
|
+
)
|
|
59
|
+
if (status !== '1' || result === null) {
|
|
60
|
+
const error =
|
|
61
|
+
typeof result === 'string' ? new Error(result) : new Error(message)
|
|
62
|
+
throw error
|
|
63
|
+
}
|
|
64
|
+
if (typeof result === 'string') {
|
|
65
|
+
throw new TypeError(result)
|
|
66
|
+
}
|
|
67
|
+
return result
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof Error && error.message === 'Max rate limit reached') {
|
|
70
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
71
|
+
return await getContractCreations({
|
|
72
|
+
apiEndpoint,
|
|
73
|
+
apiKey,
|
|
74
|
+
addresses,
|
|
75
|
+
logger,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
throw error
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { getBlockNumberOfTimestamp } from './getBlockNumberOfTimestamp'
|
|
2
2
|
export { getContractByAddress } from './getContractByAddress'
|
|
3
|
+
export { getContractCreations } from './getContractCreations'
|
|
3
4
|
export { getErc1155TokenTransfersByAddress } from './getErc1155TokenTransfersByAddress'
|
|
4
5
|
export { getErc20TokenTransfersByAddress } from './getErc20TokenTransfersByAddress'
|
|
5
6
|
export { getErc721TokenTransfersByAddress } from './getErc721TokenTransfersByAddress'
|
package/explorers/types.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type Explorer = {
|
|
|
16
16
|
logger?: Logger,
|
|
17
17
|
) => Promise<bigint>
|
|
18
18
|
readonly getContract: FunctionGetContract
|
|
19
|
+
readonly getContractCreations: FunctionGetContractCreations
|
|
19
20
|
readonly getInternalTransactionOfTransaction: FunctionGetInternalTransactionOfTransaction
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -86,6 +87,17 @@ type FunctionGetContract = (
|
|
|
86
87
|
| undefined
|
|
87
88
|
>
|
|
88
89
|
|
|
90
|
+
type FunctionGetContractCreations = (
|
|
91
|
+
addresses: readonly Hex[],
|
|
92
|
+
logger?: Logger,
|
|
93
|
+
) => Promise<
|
|
94
|
+
readonly {
|
|
95
|
+
readonly contractAddress: Hex
|
|
96
|
+
readonly contractCreator: Hex
|
|
97
|
+
readonly txHash: Hex
|
|
98
|
+
}[]
|
|
99
|
+
>
|
|
100
|
+
|
|
89
101
|
type FunctionGetInternalTransactionOfTransaction = (parameters: {
|
|
90
102
|
readonly hash: Hex
|
|
91
103
|
readonly nativeCurrency: CryptoCurrency
|