@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.
Files changed (47) hide show
  1. package/_cjs/chain/definitions/ronin.js +6 -2
  2. package/_cjs/chain/definitions/ronin.js.map +1 -1
  3. package/_cjs/client/create.js +2 -6
  4. package/_cjs/client/create.js.map +1 -1
  5. package/_cjs/explorer/index.js +7 -5
  6. package/_cjs/explorer/index.js.map +1 -1
  7. package/_cjs/explorer/moralis/client.js +64 -0
  8. package/_cjs/explorer/moralis/client.js.map +1 -0
  9. package/_cjs/explorer/moralis/create.js +146 -0
  10. package/_cjs/explorer/moralis/create.js.map +1 -0
  11. package/_cjs/explorer/moralis/getWalletTransactionHistory.js +65 -0
  12. package/_cjs/explorer/moralis/getWalletTransactionHistory.js.map +1 -0
  13. package/_esm/chain/definitions/ronin.js +7 -3
  14. package/_esm/chain/definitions/ronin.js.map +1 -1
  15. package/_esm/client/create.js +2 -6
  16. package/_esm/client/create.js.map +1 -1
  17. package/_esm/explorer/index.js +1 -0
  18. package/_esm/explorer/index.js.map +1 -1
  19. package/_esm/explorer/moralis/client.js +64 -0
  20. package/_esm/explorer/moralis/client.js.map +1 -0
  21. package/_esm/explorer/moralis/create.js +142 -0
  22. package/_esm/explorer/moralis/create.js.map +1 -0
  23. package/_esm/explorer/moralis/getWalletTransactionHistory.js +141 -0
  24. package/_esm/explorer/moralis/getWalletTransactionHistory.js.map +1 -0
  25. package/_types/chain/definitions/ronin.d.ts +5 -1
  26. package/_types/chain/definitions/ronin.d.ts.map +1 -1
  27. package/_types/client/create.d.ts.map +1 -1
  28. package/_types/explorer/index.d.ts +1 -0
  29. package/_types/explorer/index.d.ts.map +1 -1
  30. package/_types/explorer/moralis/client.d.ts +16 -0
  31. package/_types/explorer/moralis/client.d.ts.map +1 -0
  32. package/_types/explorer/moralis/create.d.ts +12 -0
  33. package/_types/explorer/moralis/create.d.ts.map +1 -0
  34. package/_types/explorer/moralis/getWalletTransactionHistory.d.ts +38 -0
  35. package/_types/explorer/moralis/getWalletTransactionHistory.d.ts.map +1 -0
  36. package/chain/definitions/ronin.ts +15 -3
  37. package/client/create.ts +2 -6
  38. package/explorer/index.ts +1 -0
  39. package/explorer/moralis/client.ts +114 -0
  40. package/explorer/moralis/create.ts +205 -0
  41. package/explorer/moralis/getWalletTransactionHistory.ts +172 -0
  42. package/package.json +1 -1
  43. package/.DS_Store +0 -0
  44. package/analyzer/.DS_Store +0 -0
  45. package/chain/.DS_Store +0 -0
  46. package/client/.DS_Store +0 -0
  47. package/explorer/.DS_Store +0 -0
@@ -0,0 +1,142 @@
1
+ import { toLowerHex, } from '../../types';
2
+ import { createInternalTransactionId } from '../../utils/createInternalTransactionId';
3
+ import { createMoralisClient } from './client';
4
+ import { getWalletTransactionHistory } from './getWalletTransactionHistory';
5
+ const limit = 100;
6
+ export const createMoralisExplorer = ({ name, baseUrl, chain, apiKey, proxyUrl, headers, }) => {
7
+ const client = createMoralisClient({
8
+ apiKey,
9
+ proxyUrl,
10
+ headers,
11
+ });
12
+ return {
13
+ name,
14
+ baseUrl,
15
+ getAddressInternalTransactions: async ({ address, fromBlock, toBlock, }) => {
16
+ const lowerAddress = toLowerHex(address);
17
+ const internalTransactions = new Map();
18
+ let cursor = undefined;
19
+ while (true) {
20
+ const result = await getWalletTransactionHistory({
21
+ client,
22
+ address: lowerAddress,
23
+ chain,
24
+ fromBlock,
25
+ toBlock,
26
+ cursor,
27
+ });
28
+ cursor = result.cursor;
29
+ for (const transaction of result.result) {
30
+ for (const internalTransaction of transaction.internal_transactions) {
31
+ if (internalTransaction.from !== lowerAddress &&
32
+ internalTransaction.to !== lowerAddress) {
33
+ continue;
34
+ }
35
+ const data = {
36
+ from: internalTransaction.from,
37
+ gas: internalTransaction.gas,
38
+ isError: false,
39
+ txHash: transaction.hash,
40
+ value: internalTransaction.value,
41
+ blockNumber: transaction.block_number,
42
+ timestamp: transaction.block_timestamp,
43
+ to: transaction.to_address,
44
+ };
45
+ const id = createInternalTransactionId(data);
46
+ if (!internalTransactions.has(id)) {
47
+ internalTransactions.set(id, data);
48
+ }
49
+ }
50
+ }
51
+ if (result.result.length < limit) {
52
+ break;
53
+ }
54
+ }
55
+ return [...internalTransactions.values()];
56
+ },
57
+ getAddressTransactionIndexes: async ({ address, fromBlock, toBlock, }) => {
58
+ const lowerAddress = toLowerHex(address);
59
+ const indexes = new Map();
60
+ let cursor = undefined;
61
+ while (true) {
62
+ const result = await getWalletTransactionHistory({
63
+ client,
64
+ address: lowerAddress,
65
+ chain,
66
+ fromBlock,
67
+ toBlock,
68
+ cursor,
69
+ });
70
+ cursor = result.cursor;
71
+ for (const transaction of result.result) {
72
+ if (transaction.from_address !== lowerAddress &&
73
+ transaction.to_address !== lowerAddress) {
74
+ continue;
75
+ }
76
+ if (!indexes.has(transaction.hash)) {
77
+ const data = {
78
+ hash: transaction.hash,
79
+ blockNumber: transaction.block_number,
80
+ timestamp: transaction.block_timestamp,
81
+ };
82
+ indexes.set(data.hash, data);
83
+ }
84
+ }
85
+ if (result.result.length < limit) {
86
+ break;
87
+ }
88
+ }
89
+ return [...indexes.values()];
90
+ },
91
+ getAddressTokenTransferIndexes: async ({ address, fromBlock, toBlock, }) => {
92
+ const lowerAddress = toLowerHex(address);
93
+ const indexes = new Map();
94
+ let cursor = undefined;
95
+ while (true) {
96
+ const result = await getWalletTransactionHistory({
97
+ client,
98
+ address: lowerAddress,
99
+ chain,
100
+ fromBlock,
101
+ toBlock,
102
+ cursor,
103
+ });
104
+ cursor = result.cursor;
105
+ for (const transaction of result.result) {
106
+ if (transaction.erc20_transfers.every(({ from_address, to_address }) => from_address !== lowerAddress && to_address !== lowerAddress) &&
107
+ transaction.nft_transfers.every(({ from_address, to_address }) => from_address !== lowerAddress && to_address !== lowerAddress)) {
108
+ continue;
109
+ }
110
+ if (!indexes.has(transaction.hash)) {
111
+ const data = {
112
+ hash: transaction.hash,
113
+ blockNumber: transaction.block_number,
114
+ timestamp: transaction.block_timestamp,
115
+ };
116
+ indexes.set(data.hash, data);
117
+ }
118
+ }
119
+ if (result.result.length < limit) {
120
+ break;
121
+ }
122
+ }
123
+ return [...indexes.values()];
124
+ },
125
+ getBlockNumberOfTimestamp: () => {
126
+ throw new Error('Function not implemented.');
127
+ },
128
+ getContract: () => {
129
+ throw new Error('Function not implemented.');
130
+ },
131
+ getContractCreations: () => {
132
+ throw new Error('Function not implemented.');
133
+ },
134
+ getEventLogs: () => {
135
+ throw new Error('Function not implemented.');
136
+ },
137
+ getInternalTransactionOfTransaction: () => {
138
+ throw new Error('Function not implemented.');
139
+ },
140
+ };
141
+ };
142
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../explorer/moralis/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,UAAU,GACX,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAA;AAErF,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAW3E,MAAM,KAAK,GAAG,GAAG,CAAA;AAEjB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EACpC,IAAI,EACJ,OAAO,EACP,KAAK,EACL,MAAM,EACN,QAAQ,EACR,OAAO,GACyB,EAAY,EAAE;IAC9C,MAAM,MAAM,GAAG,mBAAmB,CAAC;QACjC,MAAM;QACN,QAAQ;QACR,OAAO;KACR,CAAC,CAAA;IAEF,OAAO;QACL,IAAI;QACJ,OAAO;QACP,8BAA8B,EAAE,KAAK,EAAE,EACrC,OAAO,EACP,SAAS,EACT,OAAO,GACR,EAA2C,EAAE;YAC5C,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;YACxC,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAGjC,CAAA;YAEH,IAAI,MAAM,GA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C,CAAA;QAC9B,CAAC;QACD,yBAAyB,EAAE,GAAoB,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;QACD,WAAW,EAAE,GAAG,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;QACD,oBAAoB,EAAE,GAAG,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;QACD,YAAY,EAAE,GAAG,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;QACD,mCAAmC,EAAE,GAAG,EAAE;YACxC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
@@ -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,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAGxE,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,gFAAgF;IAChF,IAAI,EAAE,cAAc;IACpB,gBAAgB;IAChB,6BAA6B;IAC7B,+BAA+B;IAC/B,oCAAoC;IACpC,gEAAgE;IAChE,YAAY,EAAE,cAAc;IAC5B,8BAA8B;IAC9B,6BAA6B;IAC7B,kCAAkC;IAClC,8DAA8D;IAC9D,UAAU,EAAE,cAAc;IAC1B,4BAA4B;IAC5B,gBAAgB;IAChB,KAAK,EAAE,gBAAgB;IACvB,mBAAmB;IACnB,oBAAoB;IACpB,4CAA4C;IAC5C,gCAAgC;IAChC,oCAAoC;IACpC,yBAAyB;IACzB,iDAAiD;IACjD,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACnE,6BAA6B;IAC7B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC;IACzD,sFAAsF;IACtF,0BAA0B;IAC1B,mCAAmC;IACnC,mDAAmD;IACnD,0BAA0B;IAC1B,+BAA+B;IAC/B,uBAAuB;IACvB,aAAa,EAAE,CAAC,CAAC,KAAK,CACpB,CAAC,CAAC,MAAM,CAAC;QACP,oBAAoB;QACpB,gBAAgB;QAChB,6BAA6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K,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 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../client/create.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,KAAK,EAaX,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,CAAA;IACZ,QAAQ,EAAE,OAAO,EAAE,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,YAAY,yBAGtB,sBAAsB,KAAG,MAkT3B,CAAA"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../client/create.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,KAAK,EAaX,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,CAAA;IACZ,QAAQ,EAAE,OAAO,EAAE,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,YAAY,yBAGtB,sBAAsB,KAAG,MA8S3B,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/client/create.ts CHANGED
@@ -111,9 +111,7 @@ export const createClient = ({
111
111
  error.message.includes('Status: 503'))) ||
112
112
  (error instanceof CallExecutionError &&
113
113
  (error.message.includes('429') || error.message.includes('503'))) ||
114
- (error instanceof RpcRequestError &&
115
- (error.details.includes('Unable to perform request') ||
116
- error.details.includes('Response payload is not completed'))) ||
114
+ error instanceof RpcRequestError ||
117
115
  error instanceof JsonRpcVersionUnsupportedError ||
118
116
  error instanceof InternalRpcError ||
119
117
  (error instanceof Error &&
@@ -215,9 +213,7 @@ export const createClient = ({
215
213
  error.message.includes('Status: 503'))) ||
216
214
  (error instanceof CallExecutionError &&
217
215
  (error.message.includes('429') || error.message.includes('503'))) ||
218
- (error instanceof RpcRequestError &&
219
- (error.details.includes('Unable to perform request') ||
220
- error.details.includes('Response payload is not completed'))) ||
216
+ error instanceof RpcRequestError ||
221
217
  error instanceof JsonRpcVersionUnsupportedError ||
222
218
  error instanceof InternalRpcError ||
223
219
  (error instanceof Error &&
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
+ }