@deserialize/multi-vm-wallet 1.2.441 → 1.3.0
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/.claude/settings.local.json +12 -0
- package/SMART_WALLET_GUIDE.md +746 -0
- package/SMART_WALLET_IMPLEMENTATION.md +460 -0
- package/dist/IChainWallet.d.ts +3 -3
- package/dist/IChainWallet.js +5 -0
- package/dist/IChainWallet.js.map +1 -1
- package/dist/evm/SMART_WALLET_EXAMPLES.d.ts +20 -0
- package/dist/evm/SMART_WALLET_EXAMPLES.js +451 -0
- package/dist/evm/SMART_WALLET_EXAMPLES.js.map +1 -0
- package/dist/evm/aa-service/index.d.ts +16 -0
- package/dist/evm/aa-service/index.js +69 -0
- package/dist/evm/aa-service/index.js.map +1 -0
- package/dist/evm/aa-service/lib/account-adapter.d.ts +26 -0
- package/dist/evm/aa-service/lib/account-adapter.js +53 -0
- package/dist/evm/aa-service/lib/account-adapter.js.map +1 -0
- package/dist/evm/aa-service/lib/kernel-account.d.ts +91 -0
- package/dist/evm/aa-service/lib/kernel-account.js +251 -0
- package/dist/evm/aa-service/lib/kernel-account.js.map +1 -0
- package/dist/evm/aa-service/lib/kernel-modules.d.ts +240 -0
- package/dist/evm/aa-service/lib/kernel-modules.js +409 -0
- package/dist/evm/aa-service/lib/kernel-modules.js.map +1 -0
- package/dist/evm/aa-service/lib/session-keys.d.ts +170 -0
- package/dist/evm/aa-service/lib/session-keys.js +297 -0
- package/dist/evm/aa-service/lib/session-keys.js.map +1 -0
- package/dist/evm/aa-service/lib/type.d.ts +167 -0
- package/dist/evm/aa-service/lib/type.js +43 -0
- package/dist/evm/aa-service/lib/type.js.map +1 -0
- package/dist/evm/aa-service/services/account-abstraction.d.ts +614 -0
- package/dist/evm/aa-service/services/account-abstraction.js +754 -0
- package/dist/evm/aa-service/services/account-abstraction.js.map +1 -0
- package/dist/evm/aa-service/services/bundler.d.ts +29 -0
- package/dist/evm/aa-service/services/bundler.js +168 -0
- package/dist/evm/aa-service/services/bundler.js.map +1 -0
- package/dist/evm/evm.d.ts +67 -3
- package/dist/evm/evm.js +212 -7
- package/dist/evm/evm.js.map +1 -1
- package/dist/evm/index.d.ts +1 -0
- package/dist/evm/index.js +3 -0
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/smartWallet.d.ts +265 -0
- package/dist/evm/smartWallet.js +675 -0
- package/dist/evm/smartWallet.js.map +1 -0
- package/dist/evm/smartWallet.types.d.ts +10 -0
- package/dist/evm/smartWallet.types.js +16 -0
- package/dist/evm/smartWallet.types.js.map +1 -0
- package/dist/evm/transaction.utils.d.ts +10 -10
- package/dist/evm/transaction.utils.js +12 -8
- package/dist/evm/transaction.utils.js.map +1 -1
- package/dist/evm/transactionParsing.js +77 -1
- package/dist/evm/transactionParsing.js.map +1 -1
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +15 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/routeScan.d.ts +191 -0
- package/dist/helpers/routeScan.js +114 -0
- package/dist/helpers/routeScan.js.map +1 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/svm/svm.d.ts +4 -3
- package/dist/svm/svm.js +29 -18
- package/dist/svm/svm.js.map +1 -1
- package/dist/svm/transactionSender.js +2 -2
- package/dist/svm/transactionSender.js.map +1 -1
- package/dist/svm/utils.d.ts +4 -3
- package/dist/svm/utils.js +19 -6
- package/dist/svm/utils.js.map +1 -1
- package/dist/test.js +7 -0
- package/dist/test.js.map +1 -1
- package/dist/types.d.ts +19 -2
- package/dist/types.js.map +1 -1
- package/dist/vm.js +9 -7
- package/dist/vm.js.map +1 -1
- package/package.json +2 -2
- package/tsconfig.json +4 -3
- package/utils/IChainWallet.ts +3 -3
- package/utils/evm/SMART_WALLET_EXAMPLES.ts.bak +591 -0
- package/utils/evm/aa-service/index.ts +85 -0
- package/utils/evm/aa-service/lib/account-adapter.ts +60 -0
- package/utils/evm/aa-service/lib/kernel-account.ts +367 -0
- package/utils/evm/aa-service/lib/kernel-modules.ts +598 -0
- package/utils/evm/aa-service/lib/session-keys.ts +389 -0
- package/utils/evm/aa-service/lib/type.ts +236 -0
- package/utils/evm/aa-service/services/account-abstraction.ts +1015 -0
- package/utils/evm/aa-service/services/bundler.ts +217 -0
- package/utils/evm/evm.ts +268 -11
- package/utils/evm/index.ts +5 -1
- package/utils/evm/smartWallet.ts +797 -0
- package/utils/evm/smartWallet.types.ts +33 -0
- package/utils/evm/transaction.utils.ts +12 -10
- package/utils/evm/transactionParsing.ts +100 -14
- package/utils/helpers/index.ts +1 -0
- package/utils/helpers/routeScan.ts +397 -0
- package/utils/index.ts +0 -2
- package/utils/svm/svm.ts +50 -9
- package/utils/svm/utils.ts +52 -7
- package/utils/test.ts +7 -0
- package/utils/types.ts +24 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart Wallet Types (Re-exports from aa-service)
|
|
3
|
+
*
|
|
4
|
+
* This file re-exports types from the AA service for backwards compatibility
|
|
5
|
+
* and cleaner imports in smartWallet.ts
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type {
|
|
9
|
+
SmartWalletOptions,
|
|
10
|
+
SmartWalletTransactionResult,
|
|
11
|
+
Call,
|
|
12
|
+
SessionKeyApprovalOptions,
|
|
13
|
+
SessionKeyUsageOptions,
|
|
14
|
+
ModuleInstallOptions,
|
|
15
|
+
ModuleUninstallOptions,
|
|
16
|
+
MultiSigConfig,
|
|
17
|
+
RecoveryConfig,
|
|
18
|
+
PaymasterConfig,
|
|
19
|
+
SmartAccountInfo,
|
|
20
|
+
EntryPointVersion,
|
|
21
|
+
KernelVersion
|
|
22
|
+
} from './aa-service/lib/type';
|
|
23
|
+
|
|
24
|
+
// Export error classes (not as types, as actual classes)
|
|
25
|
+
export {
|
|
26
|
+
SmartWalletError,
|
|
27
|
+
SessionKeyError,
|
|
28
|
+
ModuleError,
|
|
29
|
+
TransactionError
|
|
30
|
+
} from './aa-service/lib/type';
|
|
31
|
+
|
|
32
|
+
export type { ModuleType } from './aa-service/lib/kernel-modules';
|
|
33
|
+
export type { SessionKeyPermissionRule, SessionKeyInfo } from './aa-service/lib/session-keys';
|
|
@@ -477,18 +477,22 @@ export async function getTokenStandard(
|
|
|
477
477
|
): Promise<TokenStandard> {
|
|
478
478
|
// Try ERC165 supportsInterface for ERC721/ERC1155
|
|
479
479
|
try {
|
|
480
|
-
|
|
480
|
+
// Check ERC721
|
|
481
|
+
const isERC721 = await client.readContract({
|
|
481
482
|
address,
|
|
482
483
|
abi: parseAbi(['function supportsInterface(bytes4) view returns (bool)']),
|
|
483
|
-
|
|
484
|
+
functionName: 'supportsInterface',
|
|
485
|
+
args: [INTERFACE_IDS.ERC721 as Hex],
|
|
484
486
|
});
|
|
485
|
-
|
|
486
|
-
// Check ERC721
|
|
487
|
-
const isERC721 = await contract.read.supportsInterface([INTERFACE_IDS.ERC721 as Hex]);
|
|
488
487
|
if (isERC721) return TokenStandard.ERC721;
|
|
489
488
|
|
|
490
489
|
// Check ERC1155
|
|
491
|
-
const isERC1155 = await
|
|
490
|
+
const isERC1155 = await client.readContract({
|
|
491
|
+
address,
|
|
492
|
+
abi: parseAbi(['function supportsInterface(bytes4) view returns (bool)']),
|
|
493
|
+
functionName: 'supportsInterface',
|
|
494
|
+
args: [INTERFACE_IDS.ERC1155 as Hex],
|
|
495
|
+
});
|
|
492
496
|
if (isERC1155) return TokenStandard.ERC1155;
|
|
493
497
|
} catch {
|
|
494
498
|
// Not ERC721/ERC1155, try ERC20
|
|
@@ -496,13 +500,11 @@ export async function getTokenStandard(
|
|
|
496
500
|
|
|
497
501
|
// Try ERC20 by checking for decimals function
|
|
498
502
|
try {
|
|
499
|
-
|
|
503
|
+
await client.readContract({
|
|
500
504
|
address,
|
|
501
505
|
abi: parseAbi(['function decimals() view returns (uint8)']),
|
|
502
|
-
|
|
506
|
+
functionName: 'decimals',
|
|
503
507
|
});
|
|
504
|
-
|
|
505
|
-
await contract.read.decimals();
|
|
506
508
|
return TokenStandard.ERC20;
|
|
507
509
|
} catch {
|
|
508
510
|
// Not a recognized token standard
|
|
@@ -12,7 +12,27 @@ import {
|
|
|
12
12
|
parseAbi
|
|
13
13
|
} from 'viem';
|
|
14
14
|
import { TRANSACTION_TYPE, TransactionType } from '../constant';
|
|
15
|
-
import { HelperAPI } from '../helpers';
|
|
15
|
+
import { HelperAPI, RouteScanAPI } from '../helpers';
|
|
16
|
+
|
|
17
|
+
// Mapping of chainId to RouteScan network name
|
|
18
|
+
const CHAIN_ID_TO_NETWORK: Record<number, string> = {
|
|
19
|
+
1: 'mainnet', // Ethereum Mainnet
|
|
20
|
+
5: 'testnet', // Goerli
|
|
21
|
+
11155111: 'testnet', // Sepolia
|
|
22
|
+
137: 'mainnet', // Polygon
|
|
23
|
+
80001: 'testnet', // Polygon Mumbai
|
|
24
|
+
56: 'mainnet', // BSC
|
|
25
|
+
97: 'testnet', // BSC Testnet
|
|
26
|
+
43114: 'mainnet', // Avalanche
|
|
27
|
+
43113: 'testnet', // Avalanche Fuji
|
|
28
|
+
42161: 'mainnet', // Arbitrum
|
|
29
|
+
421611: 'testnet', // Arbitrum Testnet
|
|
30
|
+
10: 'mainnet', // Optimism
|
|
31
|
+
420: 'testnet', // Optimism Goerli
|
|
32
|
+
8453: 'mainnet', // Base
|
|
33
|
+
84531: 'testnet', // Base Goerli
|
|
34
|
+
16661: 'mainnet', // 0G Newton Testnet (using mainnet for simplicity)
|
|
35
|
+
};
|
|
16
36
|
|
|
17
37
|
export interface EVMTransactionHistoryItem {
|
|
18
38
|
hash: string;
|
|
@@ -153,7 +173,72 @@ export async function getEVMTransactionHistory(
|
|
|
153
173
|
// }
|
|
154
174
|
if (client.chain?.id === undefined) throw new Error("Chain Id is Undefined")
|
|
155
175
|
|
|
156
|
-
|
|
176
|
+
const chainId = client.chain.id;
|
|
177
|
+
const network = CHAIN_ID_TO_NETWORK[chainId];
|
|
178
|
+
|
|
179
|
+
// Try RouteScan first if network mapping exists
|
|
180
|
+
if (network) {
|
|
181
|
+
try {
|
|
182
|
+
console.log(`Fetching transaction history from RouteScan for chain ${chainId} (${network})`);
|
|
183
|
+
const routeScanResponse = await RouteScanAPI.getTxList(
|
|
184
|
+
network,
|
|
185
|
+
chainId,
|
|
186
|
+
walletAddress,
|
|
187
|
+
0,
|
|
188
|
+
99999999,
|
|
189
|
+
1,
|
|
190
|
+
20, // limit to 20 recent transactions
|
|
191
|
+
'desc' // newest first
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (routeScanResponse.status === '1' && routeScanResponse.result) {
|
|
195
|
+
console.log(`RouteScan returned ${routeScanResponse.result.length} transactions`);
|
|
196
|
+
// Convert RouteScan format to our EVMTransactionHistoryItem format
|
|
197
|
+
return routeScanResponse.result.map(tx => ({
|
|
198
|
+
hash: tx.hash,
|
|
199
|
+
timestamp: parseInt(tx.timeStamp),
|
|
200
|
+
status: tx.txreceipt_status === '1' ? 'success' as const : 'failed' as const,
|
|
201
|
+
fee: formatEther(BigInt(tx.gasUsed) * BigInt(tx.gasPrice)),
|
|
202
|
+
type: determineTransactionTypeFromInput(tx.input, tx.value),
|
|
203
|
+
from: tx.from,
|
|
204
|
+
to: tx.to || null,
|
|
205
|
+
blockNumber: BigInt(tx.blockNumber),
|
|
206
|
+
gasUsed: BigInt(tx.gasUsed),
|
|
207
|
+
gasPrice: formatUnits(BigInt(tx.gasPrice), 9), // gwei
|
|
208
|
+
value: formatEther(BigInt(tx.value)),
|
|
209
|
+
method: tx.methodId || undefined,
|
|
210
|
+
// Token and NFT transfers would need additional API calls
|
|
211
|
+
// We'll skip them for now to keep it simple
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
console.warn('RouteScan failed, falling back to HelperAPI:', error);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Fallback to HelperAPI
|
|
220
|
+
console.log(`Fetching transaction history from HelperAPI for chain ${chainId}`);
|
|
221
|
+
return await HelperAPI.getTransactionHistory(walletAddress, "EVM", chainId);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Determine transaction type from input data and value (simpler version for RouteScan data)
|
|
226
|
+
*/
|
|
227
|
+
function determineTransactionTypeFromInput(input: string, value: string): TransactionType {
|
|
228
|
+
if (input === '0x' || input === '') {
|
|
229
|
+
return BigInt(value) > 0n ? TRANSACTION_TYPE.NATIVE_TRANSFER : TRANSACTION_TYPE.CONTRACT_INTERACTION;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const methodSig = input.slice(0, 10);
|
|
233
|
+
|
|
234
|
+
if (methodSig === '0xa9059cbb') return TRANSACTION_TYPE.TOKEN_TRANSFER; // ERC20 transfer
|
|
235
|
+
if (methodSig === '0x23b872dd') return TRANSACTION_TYPE.TOKEN_TRANSFER; // ERC20 transferFrom
|
|
236
|
+
if (methodSig === '0x42842e0e') return TRANSACTION_TYPE.NFT_TRANSFER; // ERC721 safeTransferFrom
|
|
237
|
+
if (methodSig === '0xf242432a') return TRANSACTION_TYPE.NFT_TRANSFER; // ERC1155 safeTransferFrom
|
|
238
|
+
|
|
239
|
+
if (BigInt(value) > 0n) return TRANSACTION_TYPE.NATIVE_TRANSFER;
|
|
240
|
+
|
|
241
|
+
return TRANSACTION_TYPE.CONTRACT_INTERACTION;
|
|
157
242
|
}
|
|
158
243
|
|
|
159
244
|
/**
|
|
@@ -492,9 +577,9 @@ function determineTransactionType(tx: Transaction, receipt: TransactionReceipt):
|
|
|
492
577
|
if (tx.value && tx.value > 0n) return TRANSACTION_TYPE.NATIVE_TRANSFER;
|
|
493
578
|
|
|
494
579
|
// Check logs for common patterns
|
|
495
|
-
if (receipt.logs.some(log => log.topics[0]?.includes('Swap'))) return TRANSACTION_TYPE.SWAP;
|
|
496
|
-
if (receipt.logs.some(log => log.topics[0]?.includes('Deposit'))) return TRANSACTION_TYPE.DEPOSIT;
|
|
497
|
-
if (receipt.logs.some(log => log.topics[0]?.includes('Withdraw'))) return TRANSACTION_TYPE.WITHDRAWAL;
|
|
580
|
+
if (receipt.logs.some(log => (log as any).topics[0]?.includes('Swap'))) return TRANSACTION_TYPE.SWAP;
|
|
581
|
+
if (receipt.logs.some(log => (log as any).topics[0]?.includes('Deposit'))) return TRANSACTION_TYPE.DEPOSIT;
|
|
582
|
+
if (receipt.logs.some(log => (log as any).topics[0]?.includes('Withdraw'))) return TRANSACTION_TYPE.WITHDRAWAL;
|
|
498
583
|
|
|
499
584
|
return TRANSACTION_TYPE.CONTRACT_INTERACTION;
|
|
500
585
|
}
|
|
@@ -515,13 +600,13 @@ async function parseTransferLogs(
|
|
|
515
600
|
for (const log of logs) {
|
|
516
601
|
try {
|
|
517
602
|
// Try ERC20 Transfer
|
|
518
|
-
if (includeTokenTransfers && log.topics.length === 3) {
|
|
603
|
+
if (includeTokenTransfers && (log as any).topics.length === 3) {
|
|
519
604
|
try {
|
|
520
605
|
const decoded = decodeEventLog({
|
|
521
606
|
abi: ERC20_TRANSFER_EVENT,
|
|
522
607
|
data: log.data,
|
|
523
|
-
topics: log.topics,
|
|
524
|
-
})
|
|
608
|
+
topics: (log as any).topics,
|
|
609
|
+
}) as any
|
|
525
610
|
|
|
526
611
|
if (decoded.eventName === 'Transfer') {
|
|
527
612
|
const { from, to, value } = decoded.args as any;
|
|
@@ -537,7 +622,8 @@ async function parseTransferLogs(
|
|
|
537
622
|
address: log.address,
|
|
538
623
|
abi: parseAbi(['function decimals() view returns (uint8)']),
|
|
539
624
|
functionName: 'decimals',
|
|
540
|
-
|
|
625
|
+
authorizationList: undefined
|
|
626
|
+
})
|
|
541
627
|
} catch { }
|
|
542
628
|
|
|
543
629
|
tokens.push({
|
|
@@ -554,13 +640,13 @@ async function parseTransferLogs(
|
|
|
554
640
|
}
|
|
555
641
|
|
|
556
642
|
// Try ERC721 Transfer (has indexed tokenId)
|
|
557
|
-
if (includeNFTTransfers && log.topics.length === 4) {
|
|
643
|
+
if (includeNFTTransfers && (log as any).topics.length === 4) {
|
|
558
644
|
try {
|
|
559
645
|
const decoded = decodeEventLog({
|
|
560
646
|
abi: ERC721_TRANSFER_EVENT,
|
|
561
647
|
data: log.data,
|
|
562
|
-
topics: log.topics,
|
|
563
|
-
})
|
|
648
|
+
topics: (log as any).topics,
|
|
649
|
+
}) as any
|
|
564
650
|
|
|
565
651
|
if (decoded.eventName === 'Transfer') {
|
|
566
652
|
const { from, to, tokenId } = decoded.args as any;
|
|
@@ -585,8 +671,8 @@ async function parseTransferLogs(
|
|
|
585
671
|
const decoded = decodeEventLog({
|
|
586
672
|
abi: ERC1155_TRANSFER_SINGLE_EVENT,
|
|
587
673
|
data: log.data,
|
|
588
|
-
topics: log.topics,
|
|
589
|
-
})
|
|
674
|
+
topics: (log as any).topics,
|
|
675
|
+
}) as any
|
|
590
676
|
|
|
591
677
|
if (decoded.eventName === 'TransferSingle') {
|
|
592
678
|
const { from, to, id, value } = decoded.args as any;
|
package/utils/helpers/index.ts
CHANGED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
export interface RouteScanTx {
|
|
2
|
+
blockNumber: string;
|
|
3
|
+
blockHash: string;
|
|
4
|
+
timeStamp: string;
|
|
5
|
+
hash: string;
|
|
6
|
+
nonce: string;
|
|
7
|
+
transactionIndex: string;
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
value: string;
|
|
11
|
+
gas: string;
|
|
12
|
+
gasPrice: string;
|
|
13
|
+
input: string;
|
|
14
|
+
methodId: string;
|
|
15
|
+
functionName: string;
|
|
16
|
+
contractAddress: string;
|
|
17
|
+
cumulativeGasUsed: string;
|
|
18
|
+
txreceipt_status: string;
|
|
19
|
+
gasUsed: string;
|
|
20
|
+
confirmations: string;
|
|
21
|
+
isError: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RouteScanBalanceMultiResult {
|
|
25
|
+
account: string;
|
|
26
|
+
balance: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface RouteScanTokenTx {
|
|
30
|
+
blockNumber: string;
|
|
31
|
+
timeStamp: string;
|
|
32
|
+
hash: string;
|
|
33
|
+
nonce: string;
|
|
34
|
+
blockHash: string;
|
|
35
|
+
from: string;
|
|
36
|
+
contractAddress: string;
|
|
37
|
+
to: string;
|
|
38
|
+
value: string;
|
|
39
|
+
tokenName: string;
|
|
40
|
+
tokenSymbol: string;
|
|
41
|
+
tokenDecimal: string;
|
|
42
|
+
transactionIndex: string;
|
|
43
|
+
gas: string;
|
|
44
|
+
gasPrice: string;
|
|
45
|
+
gasUsed: string;
|
|
46
|
+
cumulativeGasUsed: string;
|
|
47
|
+
input: string;
|
|
48
|
+
confirmations: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface RouteScanInternalTx {
|
|
52
|
+
blockNumber: string;
|
|
53
|
+
timeStamp: string;
|
|
54
|
+
hash: string;
|
|
55
|
+
from: string;
|
|
56
|
+
to: string;
|
|
57
|
+
value: string;
|
|
58
|
+
contractAddress: string;
|
|
59
|
+
input: string;
|
|
60
|
+
type: string;
|
|
61
|
+
gas: string;
|
|
62
|
+
gasUsed: string;
|
|
63
|
+
isError: string;
|
|
64
|
+
errCode: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface RouteScanNftTx {
|
|
68
|
+
blockNumber: string;
|
|
69
|
+
timeStamp: string;
|
|
70
|
+
hash: string;
|
|
71
|
+
nonce: string;
|
|
72
|
+
blockHash: string;
|
|
73
|
+
from: string;
|
|
74
|
+
contractAddress: string;
|
|
75
|
+
to: string;
|
|
76
|
+
tokenID: string;
|
|
77
|
+
tokenName: string;
|
|
78
|
+
tokenSymbol: string;
|
|
79
|
+
tokenDecimal: string;
|
|
80
|
+
transactionIndex: string;
|
|
81
|
+
gas: string;
|
|
82
|
+
gasPrice: string;
|
|
83
|
+
gasUsed: string;
|
|
84
|
+
cumulativeGasUsed: string;
|
|
85
|
+
input: string;
|
|
86
|
+
confirmations: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface RouteScanSourceCodeResult {
|
|
90
|
+
SourceCode: string;
|
|
91
|
+
ABI: string;
|
|
92
|
+
ContractName: string;
|
|
93
|
+
CompilerVersion: string;
|
|
94
|
+
OptimizationUsed: string;
|
|
95
|
+
Runs: string;
|
|
96
|
+
ConstructorArguments: string;
|
|
97
|
+
EVMVersion: string;
|
|
98
|
+
Library: string;
|
|
99
|
+
LicenseType: string;
|
|
100
|
+
Proxy: string;
|
|
101
|
+
Implementation: string;
|
|
102
|
+
SwarmSource: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface RouteScanTxReceiptStatus {
|
|
106
|
+
status: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface RouteScanBlockReward {
|
|
110
|
+
blockNumber: string;
|
|
111
|
+
timeStamp: string;
|
|
112
|
+
blockMiner: string;
|
|
113
|
+
blockReward: string;
|
|
114
|
+
uncles: {
|
|
115
|
+
miner: string;
|
|
116
|
+
unclePosition: string;
|
|
117
|
+
blockreward: string;
|
|
118
|
+
}[];
|
|
119
|
+
uncleInclusionReward: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface RouteScanBlockCountdown {
|
|
123
|
+
CurrentBlock: string;
|
|
124
|
+
CountdownBlock: string;
|
|
125
|
+
RemainingBlock: string;
|
|
126
|
+
EstimateTimeInSec: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface RouteScanLog {
|
|
130
|
+
address: string;
|
|
131
|
+
topics: string[];
|
|
132
|
+
data: string;
|
|
133
|
+
blockNumber: string;
|
|
134
|
+
timeStamp: string;
|
|
135
|
+
gasPrice: string;
|
|
136
|
+
gasUsed: string;
|
|
137
|
+
logIndex: string;
|
|
138
|
+
transactionHash: string;
|
|
139
|
+
transactionIndex: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface RouteScanProxyTx {
|
|
143
|
+
blockHash: string;
|
|
144
|
+
blockNumber: string;
|
|
145
|
+
from: string;
|
|
146
|
+
gas: string;
|
|
147
|
+
gasPrice: string;
|
|
148
|
+
hash: string;
|
|
149
|
+
input: string;
|
|
150
|
+
nonce: string;
|
|
151
|
+
to: string;
|
|
152
|
+
transactionIndex: string;
|
|
153
|
+
value: string;
|
|
154
|
+
v: string;
|
|
155
|
+
r: string;
|
|
156
|
+
s: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface RouteScanProxyBlock {
|
|
160
|
+
number: string;
|
|
161
|
+
hash: string;
|
|
162
|
+
parentHash: string;
|
|
163
|
+
nonce: string;
|
|
164
|
+
sha3Uncles: string;
|
|
165
|
+
logsBloom: string;
|
|
166
|
+
transactionsRoot: string;
|
|
167
|
+
stateRoot: string;
|
|
168
|
+
miner: string;
|
|
169
|
+
difficulty: string;
|
|
170
|
+
totalDifficulty: string;
|
|
171
|
+
extraData: string;
|
|
172
|
+
size: string;
|
|
173
|
+
gasLimit: string;
|
|
174
|
+
gasUsed: string;
|
|
175
|
+
timestamp: string;
|
|
176
|
+
transactions: RouteScanProxyTx[] | string[];
|
|
177
|
+
uncles: string[];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface RouteScanResponse<T> {
|
|
181
|
+
status: string;
|
|
182
|
+
message: string;
|
|
183
|
+
result: T;
|
|
184
|
+
}
|
|
185
|
+
const BASE_URL = "https://api.routescan.io/v2/network";
|
|
186
|
+
type Sort = "asc" | "desc";
|
|
187
|
+
|
|
188
|
+
export class RouteScanAPI {
|
|
189
|
+
static async getTxList(
|
|
190
|
+
network: string,
|
|
191
|
+
chainId: number,
|
|
192
|
+
address: string,
|
|
193
|
+
startblock: number = 0,
|
|
194
|
+
endblock: number = 99999999,
|
|
195
|
+
page: number = 1,
|
|
196
|
+
offset: number = 10,
|
|
197
|
+
sort: Sort = "asc"
|
|
198
|
+
): Promise<RouteScanResponse<RouteScanTx[]>> {
|
|
199
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=txlist&address=${address}&startblock=${startblock}&endblock=${endblock}&page=${page}&offset=${offset}&sort=${sort}`;
|
|
200
|
+
const res = await fetch(url);
|
|
201
|
+
const data = await res.json() as RouteScanResponse<RouteScanTx[]>;
|
|
202
|
+
return data;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
static async getBalance(
|
|
206
|
+
network: string,
|
|
207
|
+
chainId: number,
|
|
208
|
+
address: string
|
|
209
|
+
): Promise<RouteScanResponse<string>> {
|
|
210
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=balance&address=${address}&tag=latest`;
|
|
211
|
+
const res = await fetch(url);
|
|
212
|
+
const data = await res.json() as RouteScanResponse<string>;
|
|
213
|
+
return data;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
static async getBalanceMulti(
|
|
217
|
+
network: string,
|
|
218
|
+
chainId: number,
|
|
219
|
+
addresses: string[]
|
|
220
|
+
): Promise<RouteScanResponse<RouteScanBalanceMultiResult[]>> {
|
|
221
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=balancemulti&address=${addresses.join(',')}&tag=latest`;
|
|
222
|
+
const res = await fetch(url);
|
|
223
|
+
const data = await res.json() as RouteScanResponse<RouteScanBalanceMultiResult[]>;
|
|
224
|
+
return data;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static async getTokenTransfers(
|
|
228
|
+
network: string,
|
|
229
|
+
chainId: number,
|
|
230
|
+
address: string,
|
|
231
|
+
contractaddress?: string,
|
|
232
|
+
startblock: number = 0,
|
|
233
|
+
endblock: number = 99999999,
|
|
234
|
+
page: number = 1,
|
|
235
|
+
offset: number = 10,
|
|
236
|
+
sort: Sort = "asc"
|
|
237
|
+
): Promise<RouteScanResponse<RouteScanTokenTx[]>> {
|
|
238
|
+
let url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=tokentx&address=${address}&startblock=${startblock}&endblock=${endblock}&page=${page}&offset=${offset}&sort=${sort}`;
|
|
239
|
+
if (contractaddress) {
|
|
240
|
+
url += `&contractaddress=${contractaddress}`;
|
|
241
|
+
}
|
|
242
|
+
const res = await fetch(url);
|
|
243
|
+
const data = await res.json() as RouteScanResponse<RouteScanTokenTx[]>;
|
|
244
|
+
return data;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static async getInternalTxListByAddress(
|
|
248
|
+
network: string,
|
|
249
|
+
chainId: number,
|
|
250
|
+
address: string,
|
|
251
|
+
startblock: number = 0,
|
|
252
|
+
endblock: number = 99999999,
|
|
253
|
+
page: number = 1,
|
|
254
|
+
offset: number = 10,
|
|
255
|
+
sort: Sort = "asc"
|
|
256
|
+
): Promise<RouteScanResponse<RouteScanInternalTx[]>> {
|
|
257
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=txlistinternal&address=${address}&startblock=${startblock}&endblock=${endblock}&page=${page}&offset=${offset}&sort=${sort}`;
|
|
258
|
+
const res = await fetch(url);
|
|
259
|
+
const data = await res.json() as RouteScanResponse<RouteScanInternalTx[]>;
|
|
260
|
+
return data;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static async getNftTransfers(
|
|
264
|
+
network: string,
|
|
265
|
+
chainId: number,
|
|
266
|
+
address: string,
|
|
267
|
+
contractaddress?: string,
|
|
268
|
+
startblock: number = 0,
|
|
269
|
+
endblock: number = 99999999,
|
|
270
|
+
page: number = 1,
|
|
271
|
+
offset: number = 10,
|
|
272
|
+
sort: Sort = "asc"
|
|
273
|
+
): Promise<RouteScanResponse<RouteScanNftTx[]>> {
|
|
274
|
+
let url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=tokennfttx&address=${address}&startblock=${startblock}&endblock=${endblock}&page=${page}&offset=${offset}&sort=${sort}`;
|
|
275
|
+
if (contractaddress) {
|
|
276
|
+
url += `&contractaddress=${contractaddress}`;
|
|
277
|
+
}
|
|
278
|
+
const res = await fetch(url);
|
|
279
|
+
const data = await res.json() as RouteScanResponse<RouteScanNftTx[]>;
|
|
280
|
+
return data;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
static async getBalanceHistory(
|
|
284
|
+
network: string,
|
|
285
|
+
chainId: number,
|
|
286
|
+
address: string,
|
|
287
|
+
blockno: number
|
|
288
|
+
): Promise<RouteScanResponse<string>> {
|
|
289
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=account&action=balancehistory&address=${address}&blockno=${blockno}`;
|
|
290
|
+
const res = await fetch(url);
|
|
291
|
+
const data = await res.json() as RouteScanResponse<string>;
|
|
292
|
+
return data;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
static async getAbi(
|
|
296
|
+
network: string,
|
|
297
|
+
chainId: number,
|
|
298
|
+
address: string
|
|
299
|
+
): Promise<RouteScanResponse<string>> {
|
|
300
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=contract&action=getabi&address=${address}`;
|
|
301
|
+
const res = await fetch(url);
|
|
302
|
+
const data = await res.json() as RouteScanResponse<string>;
|
|
303
|
+
return data;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
static async getSourceCode(
|
|
307
|
+
network: string,
|
|
308
|
+
chainId: number,
|
|
309
|
+
address: string
|
|
310
|
+
): Promise<RouteScanResponse<RouteScanSourceCodeResult[]>> {
|
|
311
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=contract&action=getsourcecode&address=${address}`;
|
|
312
|
+
const res = await fetch(url);
|
|
313
|
+
const data = await res.json() as RouteScanResponse<RouteScanSourceCodeResult[]>;
|
|
314
|
+
return data;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
static async getTxReceiptStatus(
|
|
318
|
+
network: string,
|
|
319
|
+
chainId: number,
|
|
320
|
+
txhash: string
|
|
321
|
+
): Promise<RouteScanResponse<RouteScanTxReceiptStatus>> {
|
|
322
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=transaction&action=gettxreceiptstatus&txhash=${txhash}`;
|
|
323
|
+
const res = await fetch(url);
|
|
324
|
+
const data = await res.json() as RouteScanResponse<RouteScanTxReceiptStatus>;
|
|
325
|
+
return data;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static async getBlockReward(
|
|
329
|
+
network: string,
|
|
330
|
+
chainId: number,
|
|
331
|
+
blockno: number
|
|
332
|
+
): Promise<RouteScanResponse<RouteScanBlockReward>> {
|
|
333
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=block&action=getblockreward&blockno=${blockno}`;
|
|
334
|
+
const res = await fetch(url);
|
|
335
|
+
const data = await res.json() as RouteScanResponse<RouteScanBlockReward>;
|
|
336
|
+
return data;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
static async getBlockCountdown(
|
|
340
|
+
network: string,
|
|
341
|
+
chainId: number,
|
|
342
|
+
blockno: number
|
|
343
|
+
): Promise<RouteScanResponse<RouteScanBlockCountdown>> {
|
|
344
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=block&action=getblockcountdown&blockno=${blockno}`;
|
|
345
|
+
const res = await fetch(url);
|
|
346
|
+
const data = await res.json() as RouteScanResponse<RouteScanBlockCountdown>;
|
|
347
|
+
return data;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
static async getLogs(
|
|
351
|
+
network: string,
|
|
352
|
+
chainId: number,
|
|
353
|
+
fromBlock: number | 'latest',
|
|
354
|
+
toBlock: number | 'latest',
|
|
355
|
+
address?: string,
|
|
356
|
+
topics?: (string | null)[],
|
|
357
|
+
page: number = 1,
|
|
358
|
+
offset: number = 1000
|
|
359
|
+
): Promise<RouteScanResponse<RouteScanLog[]>> {
|
|
360
|
+
let url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=logs&action=getLogs&fromBlock=${fromBlock}&toBlock=${toBlock}&page=${page}&offset=${offset}`;
|
|
361
|
+
if (address) {
|
|
362
|
+
url += `&address=${address}`;
|
|
363
|
+
}
|
|
364
|
+
if (topics) {
|
|
365
|
+
for (let i = 0; i < topics.length; i++) {
|
|
366
|
+
if (topics[i]) {
|
|
367
|
+
url += `&topic${i}=${topics[i]}`;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
const res = await fetch(url);
|
|
372
|
+
const data = await res.json() as RouteScanResponse<RouteScanLog[]>;
|
|
373
|
+
return data;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
static async ethBlockNumber(
|
|
377
|
+
network: string,
|
|
378
|
+
chainId: number
|
|
379
|
+
): Promise<RouteScanResponse<string>> {
|
|
380
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=proxy&action=eth_blockNumber`;
|
|
381
|
+
const res = await fetch(url);
|
|
382
|
+
const data = await res.json() as RouteScanResponse<string>;
|
|
383
|
+
return data;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
static async ethGetBlockByNumber(
|
|
387
|
+
network: string,
|
|
388
|
+
chainId: number,
|
|
389
|
+
blockNumber: string,
|
|
390
|
+
fullTransactions: boolean = false
|
|
391
|
+
): Promise<RouteScanResponse<RouteScanProxyBlock>> {
|
|
392
|
+
const url = `${BASE_URL}/${network}/evm/${chainId}/etherscan/api?module=proxy&action=eth_getBlockByNumber&tag=${blockNumber}&boolean=${fullTransactions}`;
|
|
393
|
+
const res = await fetch(url);
|
|
394
|
+
const data = await res.json() as RouteScanResponse<RouteScanProxyBlock>;
|
|
395
|
+
return data;
|
|
396
|
+
}
|
|
397
|
+
}
|
package/utils/index.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from "./walletBip32"
|
|
2
|
-
export * from "./evm/evm"
|
|
3
2
|
export * from "./types"
|
|
4
3
|
export * from "./vm"
|
|
5
4
|
export * from "./evm"
|
|
6
5
|
export * from "./svm"
|
|
7
|
-
export * from "./types"
|
|
8
6
|
export * from "./constant"
|
|
9
7
|
export * from "bs58"
|
|
10
8
|
export * from "@solana/web3.js"
|