@0xtorch/evm 0.0.105 → 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.
Files changed (41) hide show
  1. package/_cjs/chain/definitions/ronin.js +6 -2
  2. package/_cjs/chain/definitions/ronin.js.map +1 -1
  3. package/_cjs/explorer/index.js +7 -5
  4. package/_cjs/explorer/index.js.map +1 -1
  5. package/_cjs/explorer/moralis/client.js +64 -0
  6. package/_cjs/explorer/moralis/client.js.map +1 -0
  7. package/_cjs/explorer/moralis/create.js +146 -0
  8. package/_cjs/explorer/moralis/create.js.map +1 -0
  9. package/_cjs/explorer/moralis/getWalletTransactionHistory.js +65 -0
  10. package/_cjs/explorer/moralis/getWalletTransactionHistory.js.map +1 -0
  11. package/_esm/chain/definitions/ronin.js +7 -3
  12. package/_esm/chain/definitions/ronin.js.map +1 -1
  13. package/_esm/explorer/index.js +1 -0
  14. package/_esm/explorer/index.js.map +1 -1
  15. package/_esm/explorer/moralis/client.js +64 -0
  16. package/_esm/explorer/moralis/client.js.map +1 -0
  17. package/_esm/explorer/moralis/create.js +142 -0
  18. package/_esm/explorer/moralis/create.js.map +1 -0
  19. package/_esm/explorer/moralis/getWalletTransactionHistory.js +141 -0
  20. package/_esm/explorer/moralis/getWalletTransactionHistory.js.map +1 -0
  21. package/_types/chain/definitions/ronin.d.ts +5 -1
  22. package/_types/chain/definitions/ronin.d.ts.map +1 -1
  23. package/_types/explorer/index.d.ts +1 -0
  24. package/_types/explorer/index.d.ts.map +1 -1
  25. package/_types/explorer/moralis/client.d.ts +16 -0
  26. package/_types/explorer/moralis/client.d.ts.map +1 -0
  27. package/_types/explorer/moralis/create.d.ts +12 -0
  28. package/_types/explorer/moralis/create.d.ts.map +1 -0
  29. package/_types/explorer/moralis/getWalletTransactionHistory.d.ts +38 -0
  30. package/_types/explorer/moralis/getWalletTransactionHistory.d.ts.map +1 -0
  31. package/chain/definitions/ronin.ts +15 -3
  32. package/explorer/index.ts +1 -0
  33. package/explorer/moralis/client.ts +114 -0
  34. package/explorer/moralis/create.ts +205 -0
  35. package/explorer/moralis/getWalletTransactionHistory.ts +172 -0
  36. package/package.json +1 -1
  37. package/.DS_Store +0 -0
  38. package/analyzer/.DS_Store +0 -0
  39. package/chain/.DS_Store +0 -0
  40. package/client/.DS_Store +0 -0
  41. package/explorer/.DS_Store +0 -0
@@ -0,0 +1,141 @@
1
+ import { z } from 'zod';
2
+ import { bigintTextSchema, lowerHexSchema } from '../../types/primitive';
3
+ const transactionSchema = z.object({
4
+ // "hash": "0x43a8a6f44f4e5b9cc9fa7e76a2b818fc76222384eb8a2fb4e3ab854523c1fb94",
5
+ hash: lowerHexSchema,
6
+ // "nonce": "1",
7
+ // "transaction_index": "27",
8
+ // "from_address_entity": null,
9
+ // "from_address_entity_logo": null,
10
+ // "from_address": "0xecdb93a95cab09b5a259ebac8fd48d3239a5589a",
11
+ from_address: lowerHexSchema,
12
+ // "from_address_label": null,
13
+ // "to_address_entity": null,
14
+ // "to_address_entity_logo": null,
15
+ // "to_address": "0x213073989821f738a7ba3520c3d31a1f9ad31bbd",
16
+ to_address: lowerHexSchema,
17
+ // "to_address_label": null,
18
+ // "value": "0",
19
+ value: bigintTextSchema,
20
+ // "gas": "392194",
21
+ // "gas_price": "0",
22
+ // "receipt_cumulative_gas_used": "4678646",
23
+ // "receipt_gas_used": "169711",
24
+ // "receipt_contract_address": null,
25
+ // "receipt_status": "1",
26
+ // "block_timestamp": "2021-07-28T15:28:09.000Z",
27
+ block_timestamp: z.string().transform((x) => new Date(x).getTime()),
28
+ // "block_number": "5304713",
29
+ block_number: z.string().regex(/^\d+$/).transform(Number),
30
+ // "block_hash": "0xb87e4ea5f85e16461ab3242413577b0e18c50d10f6f22454d3f8da850b4135d9",
31
+ // "transaction_fee": "0",
32
+ // "method_label": "settleAuction",
33
+ // "summary": "Received 0.8 WETH from 0xe3...6b4b",
34
+ // "possible_spam": false,
35
+ // "category": "token receive",
36
+ // "nft_transfers": [],
37
+ nft_transfers: z.array(z.object({
38
+ // "log_index": 132,
39
+ // "value": "0",
40
+ // "contract_type": "ERC721",
41
+ // "transaction_type": "Single",
42
+ // "token_address": "0x32950db2a7164ae833121501c797d79e7b79d74c",
43
+ // "token_id": "2273287",
44
+ // "from_address_entity": null,
45
+ // "from_address_entity_logo": null,
46
+ // "from_address": "0xecdb93a95cab09b5a259ebac8fd48d3239a5589a",
47
+ from_address: lowerHexSchema,
48
+ // "from_address_label": null,
49
+ // "to_address_entity": null,
50
+ // "to_address_entity_logo": null,
51
+ // "to_address": "0x36b9b408da80783a360ba847303b015d7e0e59f8",
52
+ to_address: lowerHexSchema,
53
+ // "to_address_label": null,
54
+ // "amount": "1",
55
+ amount: bigintTextSchema,
56
+ // "operator": null,
57
+ // "possible_spam": false,
58
+ // "verified_collection": false,
59
+ // "direction": "send"
60
+ })),
61
+ // "erc20_transfers": [],
62
+ erc20_transfers: z.array(z.object({
63
+ // "token_name": "Ronin Wrapped Ether",
64
+ // "token_symbol": "WETH",
65
+ // "token_logo": null,
66
+ // "token_decimals": "18",
67
+ // "from_address_entity": null,
68
+ // "from_address_entity_logo": null,
69
+ // "from_address": "0xecdb93a95cab09b5a259ebac8fd48d3239a5589a",
70
+ from_address: lowerHexSchema,
71
+ // "from_address_label": null,
72
+ // "to_address_entity": null,
73
+ // "to_address_entity_logo": null,
74
+ // "to_address": "0xa99cacd1427f493a95b585a5c7989a08c86a616b",
75
+ to_address: lowerHexSchema,
76
+ // "to_address_label": null,
77
+ // "address": "0xc99a6a985ed2cac1ef41640596c5a5f9f4e19ef5",
78
+ // "log_index": 37,
79
+ // "value": "6851147569444444",
80
+ value: bigintTextSchema,
81
+ // "possible_spam": false,
82
+ // "verified_contract": false,
83
+ // "security_score": null,
84
+ // "direction": "send",
85
+ // "value_formatted": "0.006851147569444444"
86
+ })),
87
+ // "native_transfers": [],
88
+ // "internal_transactions": [],
89
+ internal_transactions: z.array(z.object({
90
+ // "transaction_hash": "0x4f3c9722734098328c9c3b1fcddb9712f4dc6724c50ee2d3614aff6362eab175",
91
+ // "block_number": 21021408,
92
+ // "block_hash": "0x971595149658a4d5c2d0a2219f5019958e1a7ff2f72d7d098e144104a2a5b6a0",
93
+ // "type": "CALL",
94
+ // "from": "0x0000000000000068f116a894984e2db1123eb395",
95
+ from: lowerHexSchema,
96
+ // "to": "0x0000a26b00c1f0df003000390027140000faa719",
97
+ to: lowerHexSchema,
98
+ // "value": "1180000000000000",
99
+ value: bigintTextSchema,
100
+ // "gas": "68677",
101
+ gas: bigintTextSchema,
102
+ // "gas_used": "85",
103
+ // "input": "0x",
104
+ // "output": "0x"
105
+ })),
106
+ });
107
+ const resultSchema = z.object({
108
+ cursor: z.string(),
109
+ result: z.array(transactionSchema),
110
+ });
111
+ const cache = new Map();
112
+ export const getWalletTransactionHistory = async ({ client, address, chain, fromBlock = 0, toBlock, cursor, }) => {
113
+ const path = `/api/v2.2/wallets/${address}/history`;
114
+ const query = {
115
+ chain,
116
+ from_block: fromBlock.toString(),
117
+ include_internal_transactions: 'true',
118
+ order: 'ASC',
119
+ };
120
+ if (toBlock !== undefined) {
121
+ query.to_block = toBlock.toString();
122
+ }
123
+ if (cursor !== undefined) {
124
+ query.cursor = cursor;
125
+ }
126
+ const cacheKey = `${path}?${Object.entries(query)
127
+ .map(([k, v]) => `${k}=${v}`)
128
+ .join('&')}`;
129
+ const cached = cache.get(cacheKey);
130
+ if (cached !== undefined) {
131
+ return cached;
132
+ }
133
+ const result = await client.get({
134
+ path,
135
+ query,
136
+ resultSchema,
137
+ });
138
+ cache.set(cacheKey, result);
139
+ return result;
140
+ };
141
+ //# sourceMappingURL=getWalletTransactionHistory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWalletTransactionHistory.js","sourceRoot":"","sources":["../../../explorer/moralis/getWalletTransactionHistory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,gBAAgB,EA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GAAG,CAAC,EACb,OAAO,EACP,MAAM,GACgC,EAAE,EAAE;IAC1C,MAAM,IAAI,GAAG,qBAAqB,OAAO,UAAU,CAAA;IACnD,MAAM,KAAK,GAA2B;QACpC,KAAK;QACL,UAAU,EAAE,SAAS,CAAC,QAAQ,EAAE;QAChC,6BAA6B,EAAE,MAAM;QACrC,KAAK,EAAE,KAAK;KACb,CAAA;IACD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;IACrC,CAAC;IACD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,KAAK,CAAC,MAAM,GAAG,MAAM,CAAA;IACvB,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;SAC9C,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;SAC5B,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;IACd,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAClC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,MAAM,CAAA;IACf,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC;QAC9B,IAAI;QACJ,KAAK;QACL,YAAY;KACb,CAAC,CAAA;IACF,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAE3B,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -2,7 +2,11 @@ import { type Client } from '../../client';
2
2
  import { type Explorer } from '../../explorer';
3
3
  import type { Chain } from '../types/chain';
4
4
  import type { HttpRpc } from '../types/rpc';
5
- export declare const createRoninChain: () => Chain;
5
+ export declare const createRoninChain: ({ explorerApiKey: apiKey, explorerProxyUrl: proxyUrl, explorerHeaders: headers, }: {
6
+ explorerApiKey?: string;
7
+ explorerProxyUrl?: string;
8
+ explorerHeaders?: Record<string, string>;
9
+ }) => Chain;
6
10
  type CreateRoninChainParameters = {
7
11
  client: Client;
8
12
  explorer: Explorer;
@@ -1 +1 @@
1
- {"version":3,"file":"ronin.d.ts","sourceRoot":"","sources":["../../../chain/definitions/ronin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,KAAK,QAAQ,EAAuB,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,gBAAgB,aAUzB,CAAA;AAEJ,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,sBAAsB,0BAGhC,0BAA0B,KAAG,KAkB9B,CAAA;AAEF,eAAO,MAAM,aAAa,EAAE,OAAO,EAsBlC,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAO,CAAA"}
1
+ {"version":3,"file":"ronin.d.ts","sourceRoot":"","sources":["../../../chain/definitions/ronin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,KAAK,QAAQ,EAAyB,MAAM,gBAAgB,CAAA;AACrE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,gBAAgB,sFAI1B;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACzC,UAcG,CAAA;AAEJ,KAAK,0BAA0B,GAAG;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,sBAAsB,0BAGhC,0BAA0B,KAAG,KAkB9B,CAAA;AAEF,eAAO,MAAM,aAAa,EAAE,OAAO,EAsBlC,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAO,CAAA"}
@@ -1,5 +1,6 @@
1
1
  export { createEtherscan } from './etherscan/create';
2
2
  export type { Explorer } from './types';
3
+ export { createMoralisExplorer } from './moralis/create';
3
4
  export { createNoApiExplorer } from './noApiExplorer/create';
4
5
  export { createBlockscout } from './blockscout/create';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../explorer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../explorer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,16 @@
1
+ import type { ZodType, ZodTypeDef } from 'zod';
2
+ export type MoralisClient = {
3
+ get: <Output, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(parameters: {
4
+ path: string;
5
+ query: Record<string, string>;
6
+ resultSchema: ZodType<Output, Def, Input>;
7
+ }) => Promise<Output>;
8
+ };
9
+ type CreateMoralisClientParameters = {
10
+ apiKey?: string;
11
+ proxyUrl?: string;
12
+ headers?: Record<string, string>;
13
+ };
14
+ export declare const createMoralisClient: ({ apiKey, proxyUrl, headers, }: CreateMoralisClientParameters) => MoralisClient;
15
+ export {};
16
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../explorer/moralis/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAI9C,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,CACH,MAAM,EACN,GAAG,SAAS,UAAU,GAAG,UAAU,EACnC,KAAK,GAAG,MAAM,EACd,UAAU,EAAE;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC7B,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;KAC1C,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACtB,CAAA;AAED,KAAK,6BAA6B,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,mBAAmB,mCAI7B,6BAA6B,KAAG,aAsFlC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { Explorer } from '../types';
2
+ type CreateMoralisExplorerParameters = {
3
+ name: string;
4
+ baseUrl: string;
5
+ chain: string;
6
+ apiKey?: string;
7
+ proxyUrl?: string;
8
+ headers?: Record<string, string>;
9
+ };
10
+ export declare const createMoralisExplorer: ({ name, baseUrl, chain, apiKey, proxyUrl, headers, }: CreateMoralisExplorerParameters) => Explorer;
11
+ export {};
12
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../explorer/moralis/create.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAIxC,KAAK,+BAA+B,GAAG;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC,CAAA;AAID,eAAO,MAAM,qBAAqB,yDAO/B,+BAA+B,KAAG,QA+KpC,CAAA"}
@@ -0,0 +1,38 @@
1
+ import type { MoralisClient } from './client';
2
+ type GetWalletTransactionHistoryParameters = {
3
+ client: MoralisClient;
4
+ address: string;
5
+ chain: string;
6
+ fromBlock?: number;
7
+ toBlock?: number;
8
+ cursor?: string;
9
+ };
10
+ export declare const getWalletTransactionHistory: ({ client, address, chain, fromBlock, toBlock, cursor, }: GetWalletTransactionHistoryParameters) => Promise<{
11
+ result: {
12
+ value: bigint;
13
+ hash: `0x${Lowercase<string>}`;
14
+ from_address: `0x${Lowercase<string>}`;
15
+ to_address: `0x${Lowercase<string>}`;
16
+ block_timestamp: number;
17
+ block_number: number;
18
+ nft_transfers: {
19
+ amount: bigint;
20
+ from_address: `0x${Lowercase<string>}`;
21
+ to_address: `0x${Lowercase<string>}`;
22
+ }[];
23
+ erc20_transfers: {
24
+ value: bigint;
25
+ from_address: `0x${Lowercase<string>}`;
26
+ to_address: `0x${Lowercase<string>}`;
27
+ }[];
28
+ internal_transactions: {
29
+ from: `0x${Lowercase<string>}`;
30
+ to: `0x${Lowercase<string>}`;
31
+ value: bigint;
32
+ gas: bigint;
33
+ }[];
34
+ }[];
35
+ cursor: string;
36
+ }>;
37
+ export {};
38
+ //# sourceMappingURL=getWalletTransactionHistory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWalletTransactionHistory.d.ts","sourceRoot":"","sources":["../../../explorer/moralis/getWalletTransactionHistory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AA0H7C,KAAK,qCAAqC,GAAG;IAC3C,MAAM,EAAE,aAAa,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,2BAA2B,4DAOrC,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BvC,CAAA"}
@@ -1,19 +1,31 @@
1
1
  import { ronin } from '@0xtorch/core'
2
2
  import { ronin as viemRonin } from 'viem/chains'
3
3
  import { type Client, createClient } from '../../client'
4
- import { type Explorer, createNoApiExplorer } from '../../explorer'
4
+ import { type Explorer, createMoralisExplorer } from '../../explorer'
5
5
  import type { Chain } from '../types/chain'
6
6
  import type { HttpRpc } from '../types/rpc'
7
7
 
8
- export const createRoninChain = () =>
8
+ export const createRoninChain = ({
9
+ explorerApiKey: apiKey,
10
+ explorerProxyUrl: proxyUrl,
11
+ explorerHeaders: headers,
12
+ }: {
13
+ explorerApiKey?: string
14
+ explorerProxyUrl?: string
15
+ explorerHeaders?: Record<string, string>
16
+ }) =>
9
17
  createRoninChainCustom({
10
18
  client: createClient({
11
19
  chain: viemRonin,
12
20
  httpRpcs: roninHttpRpcs,
13
21
  }),
14
- explorer: createNoApiExplorer({
22
+ explorer: createMoralisExplorer({
15
23
  name: 'The Ronin Block Explorer',
16
24
  baseUrl: 'https://app.roninchain.com',
25
+ chain: 'ronin',
26
+ apiKey,
27
+ proxyUrl,
28
+ headers,
17
29
  }),
18
30
  })
19
31
 
package/explorer/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createEtherscan } from './etherscan/create'
2
2
  export type { Explorer } from './types'
3
+ export { createMoralisExplorer } from './moralis/create'
3
4
  export { createNoApiExplorer } from './noApiExplorer/create'
4
5
  export { createBlockscout } from './blockscout/create'
@@ -0,0 +1,114 @@
1
+ import { rest } from '@0xtorch/core'
2
+ import type { ZodType, ZodTypeDef } from 'zod'
3
+
4
+ const apiBaseUrl = 'https://deep-index.moralis.io'
5
+
6
+ export type MoralisClient = {
7
+ get: <
8
+ Output,
9
+ Def extends ZodTypeDef = ZodTypeDef,
10
+ Input = Output,
11
+ >(parameters: {
12
+ path: string
13
+ query: Record<string, string>
14
+ resultSchema: ZodType<Output, Def, Input>
15
+ }) => Promise<Output>
16
+ }
17
+
18
+ type CreateMoralisClientParameters = {
19
+ apiKey?: string
20
+ proxyUrl?: string
21
+ headers?: Record<string, string>
22
+ }
23
+
24
+ export const createMoralisClient = ({
25
+ apiKey,
26
+ proxyUrl,
27
+ headers,
28
+ }: CreateMoralisClientParameters): MoralisClient => {
29
+ // apiKey = undefined かつ proxyUrl = undefined の場合はエラー
30
+ if (apiKey === undefined && proxyUrl === undefined) {
31
+ throw new Error('apiKey or proxyUrl must be provided')
32
+ }
33
+
34
+ const rateLimitPerSecond = 1
35
+ const requestTimestamps: number[] = []
36
+
37
+ const get = async <
38
+ Output,
39
+ Def extends ZodTypeDef = ZodTypeDef,
40
+ Input = Output,
41
+ >(
42
+ {
43
+ path,
44
+ query,
45
+ resultSchema,
46
+ }: {
47
+ path: string
48
+ query: Record<string, string>
49
+ resultSchema: ZodType<Output, Def, Input>
50
+ },
51
+ repeat = 0,
52
+ ): Promise<Output> => {
53
+ // rate limit を超えていたら 1 秒待つ
54
+ const time1SecondAgo = Date.now() - 1000
55
+ if (
56
+ requestTimestamps.filter((t) => t >= time1SecondAgo).length >=
57
+ rateLimitPerSecond
58
+ ) {
59
+ await new Promise<void>((resolve) => {
60
+ const intervalId = setInterval(() => {
61
+ const time1SecondAgo = Date.now() - 1000
62
+ if (
63
+ requestTimestamps.filter((t) => t >= time1SecondAgo).length <
64
+ rateLimitPerSecond
65
+ ) {
66
+ clearInterval(intervalId)
67
+ resolve()
68
+ return
69
+ }
70
+ }, 1000)
71
+ })
72
+ }
73
+
74
+ // requestTimestamps に追加
75
+ requestTimestamps.push(Date.now())
76
+
77
+ // request
78
+ try {
79
+ const url = new URL(path, apiBaseUrl)
80
+ for (const [key, value] of Object.entries(query)) {
81
+ url.searchParams.set(key, value)
82
+ }
83
+ console.debug(`[GET] ${url.toString()}`)
84
+ const result = await rest(
85
+ proxyUrl === undefined
86
+ ? url.toString()
87
+ : `${proxyUrl}${encodeURIComponent(url.toString())}`,
88
+ {
89
+ schema: resultSchema,
90
+ fetchOptions: {
91
+ headers: {
92
+ ...headers,
93
+ ...(apiKey === undefined ? {} : { 'X-API-Key': apiKey }),
94
+ },
95
+ },
96
+ },
97
+ )
98
+ return result
99
+ } catch (error) {
100
+ if (repeat < 3 && error instanceof Error) {
101
+ if (error.message.includes('429')) {
102
+ console.debug(error)
103
+ await new Promise((resolve) => setTimeout(resolve, 10_000))
104
+ return await get({ path, query, resultSchema }, repeat + 1)
105
+ }
106
+ }
107
+ throw error
108
+ }
109
+ }
110
+
111
+ return {
112
+ get,
113
+ }
114
+ }
@@ -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
+ }