tx-indexer 0.5.4 → 0.5.5
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/dist/{client-xmDVjOy4.d.ts → client-D8iyrH5w.d.ts} +8 -3
- package/dist/client.d.ts +1 -1
- package/dist/client.js +44 -4
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +44 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -110,27 +110,32 @@ interface SpamFilterConfig {
|
|
|
110
110
|
* - Has low classification confidence
|
|
111
111
|
* - Is not relevant to the wallet
|
|
112
112
|
* - Involves dust amounts below configured thresholds
|
|
113
|
+
* - The wallet only received dust amounts (spam airdrops)
|
|
113
114
|
*
|
|
114
115
|
* @param tx - Raw transaction data
|
|
115
116
|
* @param classification - Transaction classification result
|
|
116
117
|
* @param config - Optional spam filter configuration (uses defaults if omitted)
|
|
118
|
+
* @param legs - Optional legs to check wallet involvement
|
|
119
|
+
* @param walletAddress - Optional wallet address to check involvement
|
|
117
120
|
* @returns True if the transaction should be filtered as spam
|
|
118
121
|
*/
|
|
119
|
-
declare function isSpamTransaction(tx: RawTransaction, classification: TransactionClassification, config?: SpamFilterConfig): boolean;
|
|
122
|
+
declare function isSpamTransaction(tx: RawTransaction, classification: TransactionClassification, config?: SpamFilterConfig, legs?: TxLeg[], walletAddress?: string): boolean;
|
|
120
123
|
/**
|
|
121
124
|
* Filters an array of transactions to remove spam and dust transactions.
|
|
122
125
|
*
|
|
123
126
|
* Applies spam detection criteria to each transaction while preserving
|
|
124
127
|
* additional properties in the returned array items.
|
|
125
128
|
*
|
|
126
|
-
* @param transactions - Array of transaction objects with tx and
|
|
129
|
+
* @param transactions - Array of transaction objects with tx, classification, and legs
|
|
127
130
|
* @param config - Optional spam filter configuration
|
|
131
|
+
* @param walletAddress - Optional wallet address to check for dust airdrops
|
|
128
132
|
* @returns Filtered array with spam transactions removed
|
|
129
133
|
*/
|
|
130
134
|
declare function filterSpamTransactions<T extends {
|
|
131
135
|
tx: RawTransaction;
|
|
132
136
|
classification: TransactionClassification;
|
|
133
|
-
|
|
137
|
+
legs?: TxLeg[];
|
|
138
|
+
}>(transactions: T[], config?: SpamFilterConfig, walletAddress?: string): T[];
|
|
134
139
|
|
|
135
140
|
interface WalletBalance {
|
|
136
141
|
address: string;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import '@solana/kit';
|
|
2
|
-
export { C as ClassifiedTransaction, F as FetchTransactionsConfig, b as GetTransactionOptions, G as GetTransactionsOptions, T as TxIndexer, a as TxIndexerOptions, c as createIndexer } from './client-
|
|
2
|
+
export { C as ClassifiedTransaction, F as FetchTransactionsConfig, b as GetTransactionOptions, G as GetTransactionsOptions, T as TxIndexer, a as TxIndexerOptions, c as createIndexer } from './client-D8iyrH5w.js';
|
|
3
3
|
import './classification.types-h046WjuF.js';
|
|
4
4
|
import 'zod';
|
package/dist/client.js
CHANGED
|
@@ -1897,7 +1897,7 @@ var DEFAULT_CONFIG2 = {
|
|
|
1897
1897
|
minConfidence: 0.5,
|
|
1898
1898
|
allowFailed: false
|
|
1899
1899
|
};
|
|
1900
|
-
function isSpamTransaction(tx, classification, config = {}) {
|
|
1900
|
+
function isSpamTransaction(tx, classification, config = {}, legs, walletAddress) {
|
|
1901
1901
|
const cfg = { ...DEFAULT_CONFIG2, ...config };
|
|
1902
1902
|
if (!cfg.allowFailed && tx.err) {
|
|
1903
1903
|
return true;
|
|
@@ -1911,6 +1911,11 @@ function isSpamTransaction(tx, classification, config = {}) {
|
|
|
1911
1911
|
if (isDustTransaction(classification, cfg)) {
|
|
1912
1912
|
return true;
|
|
1913
1913
|
}
|
|
1914
|
+
if (legs && walletAddress) {
|
|
1915
|
+
if (isWalletDustOnly(legs, walletAddress, cfg)) {
|
|
1916
|
+
return true;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1914
1919
|
return false;
|
|
1915
1920
|
}
|
|
1916
1921
|
function isDustTransaction(classification, config) {
|
|
@@ -1927,9 +1932,40 @@ function isDustTransaction(classification, config) {
|
|
|
1927
1932
|
}
|
|
1928
1933
|
return Math.abs(amountUi) < config.minTokenAmountUsd;
|
|
1929
1934
|
}
|
|
1930
|
-
function
|
|
1935
|
+
function isWalletDustOnly(legs, walletAddress, config) {
|
|
1936
|
+
const walletAccountId = `external:${walletAddress}`;
|
|
1937
|
+
const walletLegs = legs.filter((leg) => leg.accountId === walletAccountId);
|
|
1938
|
+
if (walletLegs.length === 0) {
|
|
1939
|
+
return false;
|
|
1940
|
+
}
|
|
1941
|
+
const sentLegs = walletLegs.filter(
|
|
1942
|
+
(leg) => leg.side === "debit" && leg.role === "sent"
|
|
1943
|
+
);
|
|
1944
|
+
for (const leg of sentLegs) {
|
|
1945
|
+
if (!isDustAmount(leg.amount.token.symbol, leg.amount.amountUi, config)) {
|
|
1946
|
+
return false;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
const receivedLegs = walletLegs.filter(
|
|
1950
|
+
(leg) => leg.side === "credit" && leg.role === "received"
|
|
1951
|
+
);
|
|
1952
|
+
for (const leg of receivedLegs) {
|
|
1953
|
+
if (!isDustAmount(leg.amount.token.symbol, leg.amount.amountUi, config)) {
|
|
1954
|
+
return false;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
return receivedLegs.length > 0;
|
|
1958
|
+
}
|
|
1959
|
+
function isDustAmount(symbol, amountUi, config) {
|
|
1960
|
+
const absAmount = Math.abs(amountUi);
|
|
1961
|
+
if (symbol === "SOL" || symbol === "WSOL") {
|
|
1962
|
+
return absAmount < config.minSolAmount;
|
|
1963
|
+
}
|
|
1964
|
+
return absAmount < config.minTokenAmountUsd;
|
|
1965
|
+
}
|
|
1966
|
+
function filterSpamTransactions(transactions, config, walletAddress) {
|
|
1931
1967
|
return transactions.filter(
|
|
1932
|
-
({ tx, classification }) => !isSpamTransaction(tx, classification, config)
|
|
1968
|
+
({ tx, classification, legs }) => !isSpamTransaction(tx, classification, config, legs, walletAddress)
|
|
1933
1969
|
);
|
|
1934
1970
|
}
|
|
1935
1971
|
|
|
@@ -2345,7 +2381,11 @@ function createIndexer(options) {
|
|
|
2345
2381
|
);
|
|
2346
2382
|
return { tx, classification, legs };
|
|
2347
2383
|
});
|
|
2348
|
-
const nonSpam = filterSpamTransactions(
|
|
2384
|
+
const nonSpam = filterSpamTransactions(
|
|
2385
|
+
classified,
|
|
2386
|
+
spamConfig,
|
|
2387
|
+
walletAddressStr
|
|
2388
|
+
);
|
|
2349
2389
|
accumulated.push(...nonSpam);
|
|
2350
2390
|
const lastSignature = signatures[signatures.length - 1];
|
|
2351
2391
|
if (lastSignature) {
|