tx-indexer 0.1.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/README.md +81 -0
- package/dist/classification.types-w82k4B1F.d.ts +212 -0
- package/dist/client-BS9KUBU7.d.ts +257 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.js +1231 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +217 -0
- package/dist/index.js +1320 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# tx-indexer SDK
|
|
2
|
+
|
|
3
|
+
Solana transaction indexer and classification SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add tx-indexer
|
|
9
|
+
# or
|
|
10
|
+
npm install tx-indexer
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createIndexer } from "tx-indexer";
|
|
17
|
+
|
|
18
|
+
const indexer = createIndexer({
|
|
19
|
+
rpcUrl: "https://api.mainnet-beta.solana.com"
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Get wallet balance
|
|
23
|
+
const balance = await indexer.getBalance("YourWalletAddress...");
|
|
24
|
+
|
|
25
|
+
// Get classified transactions
|
|
26
|
+
const txs = await indexer.getTransactions("YourWalletAddress...", {
|
|
27
|
+
limit: 10,
|
|
28
|
+
filterSpam: true
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Get single transaction
|
|
32
|
+
const tx = await indexer.getTransaction("signature...", "walletAddress...");
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Bundle Size
|
|
36
|
+
|
|
37
|
+
The SDK is lightweight and tree-shakeable:
|
|
38
|
+
|
|
39
|
+
| Import | Size (minified + brotli) |
|
|
40
|
+
|--------|----------|
|
|
41
|
+
| Full SDK | ~20 KB |
|
|
42
|
+
| `createIndexer` only | ~20 KB |
|
|
43
|
+
| `classifyTransaction` | ~3 KB |
|
|
44
|
+
| `fetchTransaction` | ~4 KB |
|
|
45
|
+
| `transactionToLegs` | ~4 KB |
|
|
46
|
+
|
|
47
|
+
Check current sizes:
|
|
48
|
+
```bash
|
|
49
|
+
bun run size
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Analyze why a bundle is large:
|
|
53
|
+
```bash
|
|
54
|
+
bun run size:why
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
See the main [project README](../../README.md) for:
|
|
60
|
+
- Complete API reference
|
|
61
|
+
- Architecture details
|
|
62
|
+
- Exported functions
|
|
63
|
+
- Usage examples
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Type check
|
|
69
|
+
bun run check-types
|
|
70
|
+
|
|
71
|
+
# Check bundle size
|
|
72
|
+
bun run size
|
|
73
|
+
|
|
74
|
+
# Analyze bundle composition
|
|
75
|
+
bun run size:why
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
|
81
|
+
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Signature } from '@solana/kit';
|
|
3
|
+
|
|
4
|
+
declare const TxDirectionSchema: z.ZodEnum<{
|
|
5
|
+
incoming: "incoming";
|
|
6
|
+
outgoing: "outgoing";
|
|
7
|
+
self: "self";
|
|
8
|
+
neutral: "neutral";
|
|
9
|
+
}>;
|
|
10
|
+
declare const TxPrimaryTypeSchema: z.ZodEnum<{
|
|
11
|
+
transfer: "transfer";
|
|
12
|
+
swap: "swap";
|
|
13
|
+
nft_purchase: "nft_purchase";
|
|
14
|
+
nft_sale: "nft_sale";
|
|
15
|
+
nft_mint: "nft_mint";
|
|
16
|
+
stake_deposit: "stake_deposit";
|
|
17
|
+
stake_withdraw: "stake_withdraw";
|
|
18
|
+
token_deposit: "token_deposit";
|
|
19
|
+
token_withdraw: "token_withdraw";
|
|
20
|
+
airdrop: "airdrop";
|
|
21
|
+
bridge_in: "bridge_in";
|
|
22
|
+
bridge_out: "bridge_out";
|
|
23
|
+
reward: "reward";
|
|
24
|
+
fee_only: "fee_only";
|
|
25
|
+
other: "other";
|
|
26
|
+
}>;
|
|
27
|
+
declare const TxCategorySchema: z.ZodEnum<{
|
|
28
|
+
transfer: "transfer";
|
|
29
|
+
other: "other";
|
|
30
|
+
fee: "fee";
|
|
31
|
+
income: "income";
|
|
32
|
+
expense: "expense";
|
|
33
|
+
investment: "investment";
|
|
34
|
+
savings: "savings";
|
|
35
|
+
refund: "refund";
|
|
36
|
+
tax: "tax";
|
|
37
|
+
}>;
|
|
38
|
+
declare const TokenBalanceSchema: z.ZodObject<{
|
|
39
|
+
accountIndex: z.ZodNumber;
|
|
40
|
+
mint: z.ZodString;
|
|
41
|
+
owner: z.ZodOptional<z.ZodString>;
|
|
42
|
+
programId: z.ZodOptional<z.ZodString>;
|
|
43
|
+
uiTokenAmount: z.ZodObject<{
|
|
44
|
+
amount: z.ZodString;
|
|
45
|
+
decimals: z.ZodNumber;
|
|
46
|
+
uiAmountString: z.ZodString;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
declare const RawTransactionSchema: z.ZodObject<{
|
|
50
|
+
signature: z.ZodCustom<Signature, Signature>;
|
|
51
|
+
slot: z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>;
|
|
52
|
+
blockTime: z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>>;
|
|
53
|
+
err: z.ZodNullable<z.ZodAny>;
|
|
54
|
+
programIds: z.ZodArray<z.ZodString>;
|
|
55
|
+
protocol: z.ZodNullable<z.ZodObject<{
|
|
56
|
+
id: z.ZodString;
|
|
57
|
+
name: z.ZodString;
|
|
58
|
+
iconUrl: z.ZodOptional<z.ZodURL>;
|
|
59
|
+
programIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
60
|
+
url: z.ZodOptional<z.ZodURL>;
|
|
61
|
+
}, z.core.$strip>>;
|
|
62
|
+
preTokenBalances: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
63
|
+
accountIndex: z.ZodNumber;
|
|
64
|
+
mint: z.ZodString;
|
|
65
|
+
owner: z.ZodOptional<z.ZodString>;
|
|
66
|
+
programId: z.ZodOptional<z.ZodString>;
|
|
67
|
+
uiTokenAmount: z.ZodObject<{
|
|
68
|
+
amount: z.ZodString;
|
|
69
|
+
decimals: z.ZodNumber;
|
|
70
|
+
uiAmountString: z.ZodString;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
}, z.core.$strip>>>;
|
|
73
|
+
postTokenBalances: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
74
|
+
accountIndex: z.ZodNumber;
|
|
75
|
+
mint: z.ZodString;
|
|
76
|
+
owner: z.ZodOptional<z.ZodString>;
|
|
77
|
+
programId: z.ZodOptional<z.ZodString>;
|
|
78
|
+
uiTokenAmount: z.ZodObject<{
|
|
79
|
+
amount: z.ZodString;
|
|
80
|
+
decimals: z.ZodNumber;
|
|
81
|
+
uiAmountString: z.ZodString;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
}, z.core.$strip>>>;
|
|
84
|
+
preBalances: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>>>;
|
|
85
|
+
postBalances: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodBigInt]>>>;
|
|
86
|
+
accountKeys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
87
|
+
memo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
88
|
+
}, z.core.$strip>;
|
|
89
|
+
declare const TxLegSideSchema: z.ZodEnum<{
|
|
90
|
+
debit: "debit";
|
|
91
|
+
credit: "credit";
|
|
92
|
+
}>;
|
|
93
|
+
declare const TxLegRoleSchema: z.ZodEnum<{
|
|
94
|
+
unknown: "unknown";
|
|
95
|
+
reward: "reward";
|
|
96
|
+
sent: "sent";
|
|
97
|
+
received: "received";
|
|
98
|
+
fee: "fee";
|
|
99
|
+
protocol_deposit: "protocol_deposit";
|
|
100
|
+
protocol_withdraw: "protocol_withdraw";
|
|
101
|
+
principal: "principal";
|
|
102
|
+
interest: "interest";
|
|
103
|
+
}>;
|
|
104
|
+
declare const TxLegSchema: z.ZodObject<{
|
|
105
|
+
accountId: z.ZodString;
|
|
106
|
+
side: z.ZodEnum<{
|
|
107
|
+
debit: "debit";
|
|
108
|
+
credit: "credit";
|
|
109
|
+
}>;
|
|
110
|
+
amount: z.ZodCustom<{
|
|
111
|
+
token: {
|
|
112
|
+
mint: string;
|
|
113
|
+
symbol: string;
|
|
114
|
+
decimals: number;
|
|
115
|
+
name?: string | undefined;
|
|
116
|
+
logoURI?: string | undefined;
|
|
117
|
+
};
|
|
118
|
+
amountRaw: string;
|
|
119
|
+
amountUi: number;
|
|
120
|
+
fiat?: {
|
|
121
|
+
currency: "USD" | "EUR";
|
|
122
|
+
amount: number;
|
|
123
|
+
pricePerUnit: number;
|
|
124
|
+
at: Date;
|
|
125
|
+
source?: string | undefined;
|
|
126
|
+
} | undefined;
|
|
127
|
+
}, {
|
|
128
|
+
token: {
|
|
129
|
+
mint: string;
|
|
130
|
+
symbol: string;
|
|
131
|
+
decimals: number;
|
|
132
|
+
name?: string | undefined;
|
|
133
|
+
logoURI?: string | undefined;
|
|
134
|
+
};
|
|
135
|
+
amountRaw: string;
|
|
136
|
+
amountUi: number;
|
|
137
|
+
fiat?: {
|
|
138
|
+
currency: "USD" | "EUR";
|
|
139
|
+
amount: number;
|
|
140
|
+
pricePerUnit: number;
|
|
141
|
+
at: Date;
|
|
142
|
+
source?: string | undefined;
|
|
143
|
+
} | undefined;
|
|
144
|
+
}>;
|
|
145
|
+
role: z.ZodEnum<{
|
|
146
|
+
unknown: "unknown";
|
|
147
|
+
reward: "reward";
|
|
148
|
+
sent: "sent";
|
|
149
|
+
received: "received";
|
|
150
|
+
fee: "fee";
|
|
151
|
+
protocol_deposit: "protocol_deposit";
|
|
152
|
+
protocol_withdraw: "protocol_withdraw";
|
|
153
|
+
principal: "principal";
|
|
154
|
+
interest: "interest";
|
|
155
|
+
}>;
|
|
156
|
+
}, z.core.$strip>;
|
|
157
|
+
type TxDirection = z.infer<typeof TxDirectionSchema>;
|
|
158
|
+
type TxPrimaryType = z.infer<typeof TxPrimaryTypeSchema>;
|
|
159
|
+
type TxCategory = z.infer<typeof TxCategorySchema>;
|
|
160
|
+
type TokenBalance = z.infer<typeof TokenBalanceSchema>;
|
|
161
|
+
type RawTransaction = z.infer<typeof RawTransactionSchema>;
|
|
162
|
+
type TxLegSide = z.infer<typeof TxLegSideSchema>;
|
|
163
|
+
type TxLegRole = z.infer<typeof TxLegRoleSchema>;
|
|
164
|
+
type TxLeg = z.infer<typeof TxLegSchema>;
|
|
165
|
+
|
|
166
|
+
declare const TransactionClassificationSchema: z.ZodObject<{
|
|
167
|
+
primaryType: z.ZodEnum<{
|
|
168
|
+
transfer: "transfer";
|
|
169
|
+
swap: "swap";
|
|
170
|
+
nft_purchase: "nft_purchase";
|
|
171
|
+
nft_sale: "nft_sale";
|
|
172
|
+
nft_mint: "nft_mint";
|
|
173
|
+
stake_deposit: "stake_deposit";
|
|
174
|
+
stake_withdraw: "stake_withdraw";
|
|
175
|
+
token_deposit: "token_deposit";
|
|
176
|
+
token_withdraw: "token_withdraw";
|
|
177
|
+
airdrop: "airdrop";
|
|
178
|
+
bridge_in: "bridge_in";
|
|
179
|
+
bridge_out: "bridge_out";
|
|
180
|
+
reward: "reward";
|
|
181
|
+
fee_only: "fee_only";
|
|
182
|
+
other: "other";
|
|
183
|
+
}>;
|
|
184
|
+
direction: z.ZodEnum<{
|
|
185
|
+
incoming: "incoming";
|
|
186
|
+
outgoing: "outgoing";
|
|
187
|
+
self: "self";
|
|
188
|
+
neutral: "neutral";
|
|
189
|
+
}>;
|
|
190
|
+
primaryAmount: z.ZodNullable<z.ZodAny>;
|
|
191
|
+
secondaryAmount: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
|
|
192
|
+
counterparty: z.ZodNullable<z.ZodObject<{
|
|
193
|
+
type: z.ZodEnum<{
|
|
194
|
+
unknown: "unknown";
|
|
195
|
+
protocol: "protocol";
|
|
196
|
+
person: "person";
|
|
197
|
+
merchant: "merchant";
|
|
198
|
+
exchange: "exchange";
|
|
199
|
+
own_wallet: "own_wallet";
|
|
200
|
+
}>;
|
|
201
|
+
address: z.ZodString;
|
|
202
|
+
name: z.ZodOptional<z.ZodString>;
|
|
203
|
+
avatarUrl: z.ZodOptional<z.ZodURL>;
|
|
204
|
+
refCode: z.ZodOptional<z.ZodString>;
|
|
205
|
+
}, z.core.$strip>>;
|
|
206
|
+
confidence: z.ZodNumber;
|
|
207
|
+
isRelevant: z.ZodOptional<z.ZodBoolean>;
|
|
208
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
209
|
+
}, z.core.$strip>;
|
|
210
|
+
type TransactionClassification = z.infer<typeof TransactionClassificationSchema>;
|
|
211
|
+
|
|
212
|
+
export { type RawTransaction as R, type TxLeg as T, type TransactionClassification as a, TxDirectionSchema as b, TxPrimaryTypeSchema as c, TxCategorySchema as d, TokenBalanceSchema as e, RawTransactionSchema as f, TxLegSchema as g, type TxDirection as h, type TxPrimaryType as i, type TxCategory as j, type TokenBalance as k, type TxLegSide as l, type TxLegRole as m, TransactionClassificationSchema as n };
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { Rpc, GetBalanceApi, GetTokenAccountsByOwnerApi, GetSignaturesForAddressApi, GetTransactionApi, RpcSubscriptions, Address, Signature } from '@solana/kit';
|
|
2
|
+
import { R as RawTransaction, T as TxLeg, a as TransactionClassification } from './classification.types-w82k4B1F.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Union type of all RPC APIs used by the transaction indexer.
|
|
6
|
+
*
|
|
7
|
+
* This ensures type safety when calling RPC methods while maintaining
|
|
8
|
+
* flexibility for the complete indexer API surface.
|
|
9
|
+
*/
|
|
10
|
+
type IndexerRpcApi = GetBalanceApi & GetTokenAccountsByOwnerApi & GetSignaturesForAddressApi & GetTransactionApi;
|
|
11
|
+
interface SolanaClient {
|
|
12
|
+
rpc: Rpc<IndexerRpcApi>;
|
|
13
|
+
rpcSubscriptions: RpcSubscriptions<any>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a Solana RPC client with both regular RPC and WebSocket subscriptions.
|
|
17
|
+
*
|
|
18
|
+
* @param rpcUrl - HTTP RPC endpoint URL
|
|
19
|
+
* @param wsUrl - Optional WebSocket URL (defaults to rpcUrl with wss:// protocol)
|
|
20
|
+
*/
|
|
21
|
+
declare function createSolanaClient(rpcUrl: string, wsUrl?: string): SolanaClient;
|
|
22
|
+
/**
|
|
23
|
+
* Parses and validates a Solana address string.
|
|
24
|
+
*
|
|
25
|
+
* @param addr - Base58-encoded Solana address
|
|
26
|
+
*/
|
|
27
|
+
declare function parseAddress(addr: string): Address;
|
|
28
|
+
/**
|
|
29
|
+
* Parses and validates a Solana transaction signature string.
|
|
30
|
+
*
|
|
31
|
+
* @param sig - Base58-encoded transaction signature
|
|
32
|
+
*/
|
|
33
|
+
declare function parseSignature(sig: string): Signature;
|
|
34
|
+
|
|
35
|
+
interface FetchTransactionsConfig {
|
|
36
|
+
limit?: number;
|
|
37
|
+
before?: Signature;
|
|
38
|
+
until?: Signature;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Fetches transaction signatures for a wallet address.
|
|
42
|
+
*
|
|
43
|
+
* @param rpc - Solana RPC client
|
|
44
|
+
* @param walletAddress - Wallet address to fetch signatures for
|
|
45
|
+
* @param config - Optional pagination and limit configuration
|
|
46
|
+
* @returns Array of raw transactions with basic metadata only
|
|
47
|
+
*/
|
|
48
|
+
declare function fetchWalletSignatures(rpc: Rpc<GetSignaturesForAddressApi>, walletAddress: Address, config?: FetchTransactionsConfig): Promise<RawTransaction[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Fetches a single transaction with full details including program IDs.
|
|
51
|
+
*
|
|
52
|
+
* @param rpc - Solana RPC client
|
|
53
|
+
* @param signature - Transaction signature
|
|
54
|
+
* @param commitment - Commitment level for fetching
|
|
55
|
+
* @returns Full raw transaction with program IDs
|
|
56
|
+
*/
|
|
57
|
+
declare function fetchTransaction(rpc: Rpc<GetTransactionApi>, signature: Signature, commitment?: "confirmed" | "finalized"): Promise<RawTransaction | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Fetches multiple transactions in parallel.
|
|
60
|
+
*
|
|
61
|
+
* @param rpc - Solana RPC client
|
|
62
|
+
* @param signatures - Array of transaction signatures
|
|
63
|
+
* @param commitment - Commitment level for fetching
|
|
64
|
+
* @returns Array of full raw transactions (nulls filtered out)
|
|
65
|
+
*/
|
|
66
|
+
declare function fetchTransactionsBatch(rpc: Rpc<GetTransactionApi>, signatures: Signature[], commitment?: "confirmed" | "finalized"): Promise<RawTransaction[]>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Converts a raw Solana transaction into a double-entry accounting ledger.
|
|
70
|
+
*
|
|
71
|
+
* Creates TxLeg entries for all SOL and token balance changes, automatically
|
|
72
|
+
* detecting and accounting for network fees. Each leg represents a debit or credit
|
|
73
|
+
* for a specific account and token, enabling transaction classification and validation.
|
|
74
|
+
*
|
|
75
|
+
* @param tx - Raw transaction data with balance changes
|
|
76
|
+
* @param walletAddress - Optional wallet address for perspective. When provided, legs are tagged
|
|
77
|
+
* as "wallet:" or "external:". When omitted (observer mode), all legs are tagged as "external:".
|
|
78
|
+
* @returns Array of transaction legs representing all balance movements
|
|
79
|
+
*/
|
|
80
|
+
declare function transactionToLegs(tx: RawTransaction, walletAddress?: Address): TxLeg[];
|
|
81
|
+
|
|
82
|
+
interface SpamFilterConfig {
|
|
83
|
+
minSolAmount?: number;
|
|
84
|
+
minTokenAmountUsd?: number;
|
|
85
|
+
minConfidence?: number;
|
|
86
|
+
allowFailed?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Determines if a transaction should be filtered as spam or dust.
|
|
90
|
+
*
|
|
91
|
+
* A transaction is considered spam if it:
|
|
92
|
+
* - Failed (and allowFailed is false)
|
|
93
|
+
* - Has low classification confidence
|
|
94
|
+
* - Is not relevant to the wallet
|
|
95
|
+
* - Involves dust amounts below configured thresholds
|
|
96
|
+
*
|
|
97
|
+
* @param tx - Raw transaction data
|
|
98
|
+
* @param classification - Transaction classification result
|
|
99
|
+
* @param config - Optional spam filter configuration (uses defaults if omitted)
|
|
100
|
+
* @returns True if the transaction should be filtered as spam
|
|
101
|
+
*/
|
|
102
|
+
declare function isSpamTransaction(tx: RawTransaction, classification: TransactionClassification, config?: SpamFilterConfig): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Filters an array of transactions to remove spam and dust transactions.
|
|
105
|
+
*
|
|
106
|
+
* Applies spam detection criteria to each transaction while preserving
|
|
107
|
+
* additional properties in the returned array items.
|
|
108
|
+
*
|
|
109
|
+
* @param transactions - Array of transaction objects with tx and classification
|
|
110
|
+
* @param config - Optional spam filter configuration
|
|
111
|
+
* @returns Filtered array with spam transactions removed
|
|
112
|
+
*/
|
|
113
|
+
declare function filterSpamTransactions<T extends {
|
|
114
|
+
tx: RawTransaction;
|
|
115
|
+
classification: TransactionClassification;
|
|
116
|
+
}>(transactions: T[], config?: SpamFilterConfig): T[];
|
|
117
|
+
|
|
118
|
+
interface WalletBalance {
|
|
119
|
+
address: string;
|
|
120
|
+
sol: {
|
|
121
|
+
lamports: bigint;
|
|
122
|
+
ui: number;
|
|
123
|
+
};
|
|
124
|
+
tokens: TokenAccountBalance[];
|
|
125
|
+
}
|
|
126
|
+
interface TokenAccountBalance {
|
|
127
|
+
mint: string;
|
|
128
|
+
tokenAccount?: string;
|
|
129
|
+
amount: {
|
|
130
|
+
raw: string;
|
|
131
|
+
ui: number;
|
|
132
|
+
};
|
|
133
|
+
decimals: number;
|
|
134
|
+
symbol: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Fetches wallet balance including SOL and SPL tokens
|
|
138
|
+
*
|
|
139
|
+
* @param rpc - Solana RPC client
|
|
140
|
+
* @param walletAddress - Wallet address to query
|
|
141
|
+
* @param tokenMints - Optional array of token mint addresses to track. If omitted, returns all tokens in wallet
|
|
142
|
+
* @returns Wallet balance data with SOL and token balances
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Fetch all tokens
|
|
146
|
+
* const allBalances = await fetchWalletBalance(rpc, address);
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* // Fetch specific tokens only
|
|
150
|
+
* const usdcOnly = await fetchWalletBalance(rpc, address, ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"]);
|
|
151
|
+
*/
|
|
152
|
+
declare function fetchWalletBalance(rpc: Rpc<GetBalanceApi & GetTokenAccountsByOwnerApi>, walletAddress: Address, tokenMints?: readonly string[]): Promise<WalletBalance>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Configuration options for creating a transaction indexer.
|
|
156
|
+
*
|
|
157
|
+
* Use either `rpcUrl` to let the SDK create a client, or provide an existing `client`
|
|
158
|
+
* to share connections across your application.
|
|
159
|
+
*/
|
|
160
|
+
type TxIndexerOptions = {
|
|
161
|
+
/** Solana RPC URL (SDK creates a new client) */
|
|
162
|
+
rpcUrl: string;
|
|
163
|
+
/** Optional WebSocket URL for subscriptions */
|
|
164
|
+
wsUrl?: string;
|
|
165
|
+
} | {
|
|
166
|
+
/** Existing Solana client to reuse (shares connections) */
|
|
167
|
+
client: SolanaClient;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Options for fetching and filtering transaction history.
|
|
171
|
+
*/
|
|
172
|
+
interface GetTransactionsOptions {
|
|
173
|
+
/** Maximum number of transactions to return (default: 10) */
|
|
174
|
+
limit?: number;
|
|
175
|
+
/** Fetch transactions before this signature (for pagination) */
|
|
176
|
+
before?: Signature;
|
|
177
|
+
/** Fetch transactions until this signature (for pagination) */
|
|
178
|
+
until?: Signature;
|
|
179
|
+
/** Whether to filter out spam transactions (default: true) */
|
|
180
|
+
filterSpam?: boolean;
|
|
181
|
+
/** Custom spam filter configuration */
|
|
182
|
+
spamConfig?: SpamFilterConfig;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A fully classified transaction with raw data, classification metadata, and accounting legs.
|
|
186
|
+
*/
|
|
187
|
+
interface ClassifiedTransaction {
|
|
188
|
+
/** Raw transaction data from the blockchain */
|
|
189
|
+
tx: RawTransaction;
|
|
190
|
+
/** Classification metadata (type, direction, amounts, counterparty) */
|
|
191
|
+
classification: TransactionClassification;
|
|
192
|
+
/** Accounting legs representing all balance movements */
|
|
193
|
+
legs: ReturnType<typeof transactionToLegs>;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Transaction indexer client for querying and classifying Solana transactions.
|
|
197
|
+
*
|
|
198
|
+
* Provides methods to fetch wallet balances, transaction history, and individual transactions
|
|
199
|
+
* with automatic protocol detection and classification.
|
|
200
|
+
*/
|
|
201
|
+
interface TxIndexer {
|
|
202
|
+
/** Direct access to the underlying Solana RPC client */
|
|
203
|
+
rpc: ReturnType<typeof createSolanaClient>["rpc"];
|
|
204
|
+
/**
|
|
205
|
+
* Fetches the SOL and SPL token balances for a wallet.
|
|
206
|
+
*
|
|
207
|
+
* @param walletAddress - Wallet address to query balances for
|
|
208
|
+
* @param tokenMints - Optional array of token mint addresses to filter
|
|
209
|
+
* @returns Wallet balance data including SOL and token balances
|
|
210
|
+
*/
|
|
211
|
+
getBalance(walletAddress: Address, tokenMints?: readonly string[]): Promise<WalletBalance>;
|
|
212
|
+
/**
|
|
213
|
+
* Fetches and classifies transaction history for a wallet.
|
|
214
|
+
*
|
|
215
|
+
* @param walletAddress - Wallet address to fetch transaction history for
|
|
216
|
+
* @param options - Configuration options for fetching and filtering
|
|
217
|
+
* @returns Array of classified transactions with full metadata
|
|
218
|
+
*/
|
|
219
|
+
getTransactions(walletAddress: Address, options?: GetTransactionsOptions): Promise<ClassifiedTransaction[]>;
|
|
220
|
+
/**
|
|
221
|
+
* Fetches and classifies a single transaction by its signature.
|
|
222
|
+
*
|
|
223
|
+
* @param signature - Transaction signature to fetch
|
|
224
|
+
* @param walletAddress - Optional wallet address for classification perspective.
|
|
225
|
+
* When omitted, returns classification from observer mode (neutral perspective).
|
|
226
|
+
* @returns Classified transaction with full metadata, or null if transaction not found
|
|
227
|
+
*/
|
|
228
|
+
getTransaction(signature: Signature, walletAddress?: Address): Promise<ClassifiedTransaction | null>;
|
|
229
|
+
/**
|
|
230
|
+
* Fetches a raw transaction without classification.
|
|
231
|
+
*
|
|
232
|
+
* @param signature - Transaction signature to fetch
|
|
233
|
+
* @returns Raw transaction data from the blockchain, or null if not found
|
|
234
|
+
*/
|
|
235
|
+
getRawTransaction(signature: Signature): Promise<RawTransaction | null>;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Creates a transaction indexer client for querying and classifying Solana transactions.
|
|
239
|
+
*
|
|
240
|
+
* Accepts either an RPC URL (SDK creates client) or an existing SolanaClient (for sharing
|
|
241
|
+
* connections across your app or with React providers).
|
|
242
|
+
*
|
|
243
|
+
* @param options - Configuration with RPC URL or existing client
|
|
244
|
+
* @returns Transaction indexer client
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* // Option 1: SDK creates client
|
|
248
|
+
* const indexer = createIndexer({ rpcUrl: "https://api.mainnet-beta.solana.com" });
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* // Option 2: Provide existing client (share connections)
|
|
252
|
+
* const myClient = createSolanaClient("https://...");
|
|
253
|
+
* const indexer = createIndexer({ client: myClient });
|
|
254
|
+
*/
|
|
255
|
+
declare function createIndexer(options: TxIndexerOptions): TxIndexer;
|
|
256
|
+
|
|
257
|
+
export { type ClassifiedTransaction as C, type FetchTransactionsConfig as F, type GetTransactionsOptions as G, type IndexerRpcApi as I, type SolanaClient as S, type TxIndexer as T, type WalletBalance as W, type TxIndexerOptions as a, createSolanaClient as b, createIndexer as c, parseSignature as d, type TokenAccountBalance as e, fetchWalletBalance as f, fetchWalletSignatures as g, fetchTransaction as h, fetchTransactionsBatch as i, isSpamTransaction as j, filterSpamTransactions as k, type SpamFilterConfig as l, parseAddress as p, transactionToLegs as t };
|
package/dist/client.d.ts
ADDED