@0xtorch/evm 0.0.104 → 0.0.106
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/chain/definitions/ronin.js +6 -2
- package/_cjs/chain/definitions/ronin.js.map +1 -1
- package/_cjs/client/create.js +2 -6
- package/_cjs/client/create.js.map +1 -1
- package/_cjs/explorer/index.js +7 -5
- package/_cjs/explorer/index.js.map +1 -1
- package/_cjs/explorer/moralis/client.js +64 -0
- package/_cjs/explorer/moralis/client.js.map +1 -0
- package/_cjs/explorer/moralis/create.js +146 -0
- package/_cjs/explorer/moralis/create.js.map +1 -0
- package/_cjs/explorer/moralis/getWalletTransactionHistory.js +65 -0
- package/_cjs/explorer/moralis/getWalletTransactionHistory.js.map +1 -0
- package/_esm/chain/definitions/ronin.js +7 -3
- package/_esm/chain/definitions/ronin.js.map +1 -1
- package/_esm/client/create.js +2 -6
- package/_esm/client/create.js.map +1 -1
- package/_esm/explorer/index.js +1 -0
- package/_esm/explorer/index.js.map +1 -1
- package/_esm/explorer/moralis/client.js +64 -0
- package/_esm/explorer/moralis/client.js.map +1 -0
- package/_esm/explorer/moralis/create.js +142 -0
- package/_esm/explorer/moralis/create.js.map +1 -0
- package/_esm/explorer/moralis/getWalletTransactionHistory.js +141 -0
- package/_esm/explorer/moralis/getWalletTransactionHistory.js.map +1 -0
- package/_types/chain/definitions/ronin.d.ts +5 -1
- package/_types/chain/definitions/ronin.d.ts.map +1 -1
- package/_types/client/create.d.ts.map +1 -1
- package/_types/explorer/index.d.ts +1 -0
- package/_types/explorer/index.d.ts.map +1 -1
- package/_types/explorer/moralis/client.d.ts +16 -0
- package/_types/explorer/moralis/client.d.ts.map +1 -0
- package/_types/explorer/moralis/create.d.ts +12 -0
- package/_types/explorer/moralis/create.d.ts.map +1 -0
- package/_types/explorer/moralis/getWalletTransactionHistory.d.ts +38 -0
- package/_types/explorer/moralis/getWalletTransactionHistory.d.ts.map +1 -0
- package/chain/definitions/ronin.ts +15 -3
- package/client/create.ts +2 -6
- package/explorer/index.ts +1 -0
- package/explorer/moralis/client.ts +114 -0
- package/explorer/moralis/create.ts +205 -0
- package/explorer/moralis/getWalletTransactionHistory.ts +172 -0
- package/package.json +1 -1
- package/.DS_Store +0 -0
- package/analyzer/.DS_Store +0 -0
- package/chain/.DS_Store +0 -0
- package/client/.DS_Store +0 -0
- package/explorer/.DS_Store +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type InternalTransactionWithIndex,
|
|
3
|
+
type LowerHex,
|
|
4
|
+
type TransactionIndex,
|
|
5
|
+
toLowerHex,
|
|
6
|
+
} from '../../types'
|
|
7
|
+
import { createInternalTransactionId } from '../../utils/createInternalTransactionId'
|
|
8
|
+
import type { Explorer } from '../types'
|
|
9
|
+
import { createMoralisClient } from './client'
|
|
10
|
+
import { getWalletTransactionHistory } from './getWalletTransactionHistory'
|
|
11
|
+
|
|
12
|
+
type CreateMoralisExplorerParameters = {
|
|
13
|
+
name: string
|
|
14
|
+
baseUrl: string
|
|
15
|
+
chain: string
|
|
16
|
+
apiKey?: string
|
|
17
|
+
proxyUrl?: string
|
|
18
|
+
headers?: Record<string, string>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const limit = 100
|
|
22
|
+
|
|
23
|
+
export const createMoralisExplorer = ({
|
|
24
|
+
name,
|
|
25
|
+
baseUrl,
|
|
26
|
+
chain,
|
|
27
|
+
apiKey,
|
|
28
|
+
proxyUrl,
|
|
29
|
+
headers,
|
|
30
|
+
}: CreateMoralisExplorerParameters): Explorer => {
|
|
31
|
+
const client = createMoralisClient({
|
|
32
|
+
apiKey,
|
|
33
|
+
proxyUrl,
|
|
34
|
+
headers,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
baseUrl,
|
|
40
|
+
getAddressInternalTransactions: async ({
|
|
41
|
+
address,
|
|
42
|
+
fromBlock,
|
|
43
|
+
toBlock,
|
|
44
|
+
}): Promise<InternalTransactionWithIndex[]> => {
|
|
45
|
+
const lowerAddress = toLowerHex(address)
|
|
46
|
+
const internalTransactions = new Map<
|
|
47
|
+
string,
|
|
48
|
+
InternalTransactionWithIndex
|
|
49
|
+
>()
|
|
50
|
+
|
|
51
|
+
let cursor: string | undefined = undefined
|
|
52
|
+
while (true) {
|
|
53
|
+
const result = await getWalletTransactionHistory({
|
|
54
|
+
client,
|
|
55
|
+
address: lowerAddress,
|
|
56
|
+
chain,
|
|
57
|
+
fromBlock,
|
|
58
|
+
toBlock,
|
|
59
|
+
cursor,
|
|
60
|
+
})
|
|
61
|
+
cursor = result.cursor
|
|
62
|
+
|
|
63
|
+
for (const transaction of result.result) {
|
|
64
|
+
for (const internalTransaction of transaction.internal_transactions) {
|
|
65
|
+
if (
|
|
66
|
+
internalTransaction.from !== lowerAddress &&
|
|
67
|
+
internalTransaction.to !== lowerAddress
|
|
68
|
+
) {
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
const data: InternalTransactionWithIndex = {
|
|
72
|
+
from: internalTransaction.from,
|
|
73
|
+
gas: internalTransaction.gas,
|
|
74
|
+
isError: false,
|
|
75
|
+
txHash: transaction.hash,
|
|
76
|
+
value: internalTransaction.value,
|
|
77
|
+
blockNumber: transaction.block_number,
|
|
78
|
+
timestamp: transaction.block_timestamp,
|
|
79
|
+
to: transaction.to_address,
|
|
80
|
+
}
|
|
81
|
+
const id = createInternalTransactionId(data)
|
|
82
|
+
if (!internalTransactions.has(id)) {
|
|
83
|
+
internalTransactions.set(id, data)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (result.result.length < limit) {
|
|
89
|
+
break
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return [...internalTransactions.values()]
|
|
94
|
+
},
|
|
95
|
+
getAddressTransactionIndexes: async ({
|
|
96
|
+
address,
|
|
97
|
+
fromBlock,
|
|
98
|
+
toBlock,
|
|
99
|
+
}): Promise<TransactionIndex[]> => {
|
|
100
|
+
const lowerAddress = toLowerHex(address)
|
|
101
|
+
const indexes = new Map<LowerHex, TransactionIndex>()
|
|
102
|
+
|
|
103
|
+
let cursor: string | undefined = undefined
|
|
104
|
+
while (true) {
|
|
105
|
+
const result = await getWalletTransactionHistory({
|
|
106
|
+
client,
|
|
107
|
+
address: lowerAddress,
|
|
108
|
+
chain,
|
|
109
|
+
fromBlock,
|
|
110
|
+
toBlock,
|
|
111
|
+
cursor,
|
|
112
|
+
})
|
|
113
|
+
cursor = result.cursor
|
|
114
|
+
|
|
115
|
+
for (const transaction of result.result) {
|
|
116
|
+
if (
|
|
117
|
+
transaction.from_address !== lowerAddress &&
|
|
118
|
+
transaction.to_address !== lowerAddress
|
|
119
|
+
) {
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
if (!indexes.has(transaction.hash)) {
|
|
123
|
+
const data: TransactionIndex = {
|
|
124
|
+
hash: transaction.hash,
|
|
125
|
+
blockNumber: transaction.block_number,
|
|
126
|
+
timestamp: transaction.block_timestamp,
|
|
127
|
+
}
|
|
128
|
+
indexes.set(data.hash, data)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (result.result.length < limit) {
|
|
133
|
+
break
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return [...indexes.values()]
|
|
138
|
+
},
|
|
139
|
+
getAddressTokenTransferIndexes: async ({
|
|
140
|
+
address,
|
|
141
|
+
fromBlock,
|
|
142
|
+
toBlock,
|
|
143
|
+
}): Promise<TransactionIndex[]> => {
|
|
144
|
+
const lowerAddress = toLowerHex(address)
|
|
145
|
+
const indexes = new Map<LowerHex, TransactionIndex>()
|
|
146
|
+
|
|
147
|
+
let cursor: string | undefined = undefined
|
|
148
|
+
while (true) {
|
|
149
|
+
const result = await getWalletTransactionHistory({
|
|
150
|
+
client,
|
|
151
|
+
address: lowerAddress,
|
|
152
|
+
chain,
|
|
153
|
+
fromBlock,
|
|
154
|
+
toBlock,
|
|
155
|
+
cursor,
|
|
156
|
+
})
|
|
157
|
+
cursor = result.cursor
|
|
158
|
+
|
|
159
|
+
for (const transaction of result.result) {
|
|
160
|
+
if (
|
|
161
|
+
transaction.erc20_transfers.every(
|
|
162
|
+
({ from_address, to_address }) =>
|
|
163
|
+
from_address !== lowerAddress && to_address !== lowerAddress,
|
|
164
|
+
) &&
|
|
165
|
+
transaction.nft_transfers.every(
|
|
166
|
+
({ from_address, to_address }) =>
|
|
167
|
+
from_address !== lowerAddress && to_address !== lowerAddress,
|
|
168
|
+
)
|
|
169
|
+
) {
|
|
170
|
+
continue
|
|
171
|
+
}
|
|
172
|
+
if (!indexes.has(transaction.hash)) {
|
|
173
|
+
const data: TransactionIndex = {
|
|
174
|
+
hash: transaction.hash,
|
|
175
|
+
blockNumber: transaction.block_number,
|
|
176
|
+
timestamp: transaction.block_timestamp,
|
|
177
|
+
}
|
|
178
|
+
indexes.set(data.hash, data)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (result.result.length < limit) {
|
|
183
|
+
break
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return [...indexes.values()]
|
|
188
|
+
},
|
|
189
|
+
getBlockNumberOfTimestamp: (): Promise<number> => {
|
|
190
|
+
throw new Error('Function not implemented.')
|
|
191
|
+
},
|
|
192
|
+
getContract: () => {
|
|
193
|
+
throw new Error('Function not implemented.')
|
|
194
|
+
},
|
|
195
|
+
getContractCreations: () => {
|
|
196
|
+
throw new Error('Function not implemented.')
|
|
197
|
+
},
|
|
198
|
+
getEventLogs: () => {
|
|
199
|
+
throw new Error('Function not implemented.')
|
|
200
|
+
},
|
|
201
|
+
getInternalTransactionOfTransaction: () => {
|
|
202
|
+
throw new Error('Function not implemented.')
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { bigintTextSchema, lowerHexSchema } from '../../types/primitive'
|
|
3
|
+
import type { MoralisClient } from './client'
|
|
4
|
+
|
|
5
|
+
const transactionSchema = z.object({
|
|
6
|
+
// "hash": "0x43a8a6f44f4e5b9cc9fa7e76a2b818fc76222384eb8a2fb4e3ab854523c1fb94",
|
|
7
|
+
hash: lowerHexSchema,
|
|
8
|
+
// "nonce": "1",
|
|
9
|
+
// "transaction_index": "27",
|
|
10
|
+
// "from_address_entity": null,
|
|
11
|
+
// "from_address_entity_logo": null,
|
|
12
|
+
// "from_address": "0xecdb93a95cab09b5a259ebac8fd48d3239a5589a",
|
|
13
|
+
from_address: lowerHexSchema,
|
|
14
|
+
// "from_address_label": null,
|
|
15
|
+
// "to_address_entity": null,
|
|
16
|
+
// "to_address_entity_logo": null,
|
|
17
|
+
// "to_address": "0x213073989821f738a7ba3520c3d31a1f9ad31bbd",
|
|
18
|
+
to_address: lowerHexSchema,
|
|
19
|
+
// "to_address_label": null,
|
|
20
|
+
// "value": "0",
|
|
21
|
+
value: bigintTextSchema,
|
|
22
|
+
// "gas": "392194",
|
|
23
|
+
// "gas_price": "0",
|
|
24
|
+
// "receipt_cumulative_gas_used": "4678646",
|
|
25
|
+
// "receipt_gas_used": "169711",
|
|
26
|
+
// "receipt_contract_address": null,
|
|
27
|
+
// "receipt_status": "1",
|
|
28
|
+
// "block_timestamp": "2021-07-28T15:28:09.000Z",
|
|
29
|
+
block_timestamp: z.string().transform((x) => new Date(x).getTime()),
|
|
30
|
+
// "block_number": "5304713",
|
|
31
|
+
block_number: z.string().regex(/^\d+$/).transform(Number),
|
|
32
|
+
// "block_hash": "0xb87e4ea5f85e16461ab3242413577b0e18c50d10f6f22454d3f8da850b4135d9",
|
|
33
|
+
// "transaction_fee": "0",
|
|
34
|
+
// "method_label": "settleAuction",
|
|
35
|
+
// "summary": "Received 0.8 WETH from 0xe3...6b4b",
|
|
36
|
+
// "possible_spam": false,
|
|
37
|
+
// "category": "token receive",
|
|
38
|
+
// "nft_transfers": [],
|
|
39
|
+
nft_transfers: z.array(
|
|
40
|
+
z.object({
|
|
41
|
+
// "log_index": 132,
|
|
42
|
+
// "value": "0",
|
|
43
|
+
// "contract_type": "ERC721",
|
|
44
|
+
// "transaction_type": "Single",
|
|
45
|
+
// "token_address": "0x32950db2a7164ae833121501c797d79e7b79d74c",
|
|
46
|
+
// "token_id": "2273287",
|
|
47
|
+
// "from_address_entity": null,
|
|
48
|
+
// "from_address_entity_logo": null,
|
|
49
|
+
// "from_address": "0xecdb93a95cab09b5a259ebac8fd48d3239a5589a",
|
|
50
|
+
from_address: lowerHexSchema,
|
|
51
|
+
// "from_address_label": null,
|
|
52
|
+
// "to_address_entity": null,
|
|
53
|
+
// "to_address_entity_logo": null,
|
|
54
|
+
// "to_address": "0x36b9b408da80783a360ba847303b015d7e0e59f8",
|
|
55
|
+
to_address: lowerHexSchema,
|
|
56
|
+
// "to_address_label": null,
|
|
57
|
+
// "amount": "1",
|
|
58
|
+
amount: bigintTextSchema,
|
|
59
|
+
// "operator": null,
|
|
60
|
+
// "possible_spam": false,
|
|
61
|
+
// "verified_collection": false,
|
|
62
|
+
// "direction": "send"
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
// "erc20_transfers": [],
|
|
66
|
+
erc20_transfers: z.array(
|
|
67
|
+
z.object({
|
|
68
|
+
// "token_name": "Ronin Wrapped Ether",
|
|
69
|
+
// "token_symbol": "WETH",
|
|
70
|
+
// "token_logo": null,
|
|
71
|
+
// "token_decimals": "18",
|
|
72
|
+
// "from_address_entity": null,
|
|
73
|
+
// "from_address_entity_logo": null,
|
|
74
|
+
// "from_address": "0xecdb93a95cab09b5a259ebac8fd48d3239a5589a",
|
|
75
|
+
from_address: lowerHexSchema,
|
|
76
|
+
// "from_address_label": null,
|
|
77
|
+
// "to_address_entity": null,
|
|
78
|
+
// "to_address_entity_logo": null,
|
|
79
|
+
// "to_address": "0xa99cacd1427f493a95b585a5c7989a08c86a616b",
|
|
80
|
+
to_address: lowerHexSchema,
|
|
81
|
+
// "to_address_label": null,
|
|
82
|
+
// "address": "0xc99a6a985ed2cac1ef41640596c5a5f9f4e19ef5",
|
|
83
|
+
// "log_index": 37,
|
|
84
|
+
// "value": "6851147569444444",
|
|
85
|
+
value: bigintTextSchema,
|
|
86
|
+
// "possible_spam": false,
|
|
87
|
+
// "verified_contract": false,
|
|
88
|
+
// "security_score": null,
|
|
89
|
+
// "direction": "send",
|
|
90
|
+
// "value_formatted": "0.006851147569444444"
|
|
91
|
+
}),
|
|
92
|
+
),
|
|
93
|
+
// "native_transfers": [],
|
|
94
|
+
// "internal_transactions": [],
|
|
95
|
+
internal_transactions: z.array(
|
|
96
|
+
z.object({
|
|
97
|
+
// "transaction_hash": "0x4f3c9722734098328c9c3b1fcddb9712f4dc6724c50ee2d3614aff6362eab175",
|
|
98
|
+
// "block_number": 21021408,
|
|
99
|
+
// "block_hash": "0x971595149658a4d5c2d0a2219f5019958e1a7ff2f72d7d098e144104a2a5b6a0",
|
|
100
|
+
// "type": "CALL",
|
|
101
|
+
// "from": "0x0000000000000068f116a894984e2db1123eb395",
|
|
102
|
+
from: lowerHexSchema,
|
|
103
|
+
// "to": "0x0000a26b00c1f0df003000390027140000faa719",
|
|
104
|
+
to: lowerHexSchema,
|
|
105
|
+
// "value": "1180000000000000",
|
|
106
|
+
value: bigintTextSchema,
|
|
107
|
+
// "gas": "68677",
|
|
108
|
+
gas: bigintTextSchema,
|
|
109
|
+
// "gas_used": "85",
|
|
110
|
+
// "input": "0x",
|
|
111
|
+
// "output": "0x"
|
|
112
|
+
}),
|
|
113
|
+
),
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const resultSchema = z.object({
|
|
117
|
+
cursor: z.string(),
|
|
118
|
+
result: z.array(transactionSchema),
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
type Result = z.infer<typeof resultSchema>
|
|
122
|
+
|
|
123
|
+
const cache = new Map<string, Result>()
|
|
124
|
+
|
|
125
|
+
type GetWalletTransactionHistoryParameters = {
|
|
126
|
+
client: MoralisClient
|
|
127
|
+
address: string
|
|
128
|
+
chain: string
|
|
129
|
+
fromBlock?: number
|
|
130
|
+
toBlock?: number
|
|
131
|
+
cursor?: string
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const getWalletTransactionHistory = async ({
|
|
135
|
+
client,
|
|
136
|
+
address,
|
|
137
|
+
chain,
|
|
138
|
+
fromBlock = 0,
|
|
139
|
+
toBlock,
|
|
140
|
+
cursor,
|
|
141
|
+
}: GetWalletTransactionHistoryParameters) => {
|
|
142
|
+
const path = `/api/v2.2/wallets/${address}/history`
|
|
143
|
+
const query: Record<string, string> = {
|
|
144
|
+
chain,
|
|
145
|
+
from_block: fromBlock.toString(),
|
|
146
|
+
include_internal_transactions: 'true',
|
|
147
|
+
order: 'ASC',
|
|
148
|
+
}
|
|
149
|
+
if (toBlock !== undefined) {
|
|
150
|
+
query.to_block = toBlock.toString()
|
|
151
|
+
}
|
|
152
|
+
if (cursor !== undefined) {
|
|
153
|
+
query.cursor = cursor
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const cacheKey = `${path}?${Object.entries(query)
|
|
157
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
158
|
+
.join('&')}`
|
|
159
|
+
const cached = cache.get(cacheKey)
|
|
160
|
+
if (cached !== undefined) {
|
|
161
|
+
return cached
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const result = await client.get({
|
|
165
|
+
path,
|
|
166
|
+
query,
|
|
167
|
+
resultSchema,
|
|
168
|
+
})
|
|
169
|
+
cache.set(cacheKey, result)
|
|
170
|
+
|
|
171
|
+
return result
|
|
172
|
+
}
|
package/package.json
CHANGED
package/.DS_Store
DELETED
|
Binary file
|
package/analyzer/.DS_Store
DELETED
|
Binary file
|
package/chain/.DS_Store
DELETED
|
Binary file
|
package/client/.DS_Store
DELETED
|
Binary file
|
package/explorer/.DS_Store
DELETED
|
Binary file
|