1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//! Liquidity analysis from DexScreener: total liquidity, liquidity-vs-FDV,
//! pair age, socials, buy/sell pressure and price-change buckets (dashboard
//! chart fodder), plus the LP-safety posture per venue.
use crate::chain::dexscreener::{liq, DexPair};
use crate::chain::SolClient;
use crate::types::{Flag, Severity};
use serde_json::json;
pub struct LiquidityAnalysis {
pub pool_addresses: Vec<String>,
pub total_liquidity_usd: f64,
pub pair_count: usize,
pub top_dex: Option<String>,
pub flags: Vec<Flag>,
pub section: serde_json::Value,
pub fetch_error: Option<String>,
}
fn round2(n: f64) -> f64 {
(n * 100.0).round() / 100.0
}
pub async fn analyze(client: &SolClient, mint: &str, now_ms: i64) -> LiquidityAnalysis {
let mut flags = vec![];
// "API failed" and "no pairs" are different answers: an empty Ok means the
// token genuinely has no indexed pair (hard-fail); an Err means we don't
// know — soft flag + warning, never hard-fail.
let (pairs, quote_side_volume, dropped_mispriced, fetch_error): (
Vec<DexPair>,
f64,
usize,
Option<String>,
) = match client.pairs_for_token(mint).await {
Ok(ps) => (
ps.pairs,
ps.quote_side_volume_24h,
ps.dropped_mispriced,
None,
),
Err(e) => (vec![], 0.0, 0, Some(e.to_string())),
};
if let Some(err) = &fetch_error {
flags.push(Flag::new(
"liquidity_unknown",
Severity::Warning,
"Liquidity could not be verified",
format!("DexScreener unreachable ({err}) — liquidity, FDV ratio and pair age were not assessed. Re-run before trusting."),
5,
));
return LiquidityAnalysis {
pool_addresses: vec![],
total_liquidity_usd: 0.0,
pair_count: 0,
top_dex: None,
flags,
section: json!({"fetchError": err, "pairs": []}),
fetch_error,
};
}
// NOTE: `pairs` arrives already stripped of mispriced outliers by
// `pairs_for_token`, so both of these are sums/reads over TRUSTED pairs
// only. That is load-bearing: `top` drives FDV, and taking it from a
// mispriced pool published a $6.7 TRILLION FDV for JUP (true $1.33B) next
// to a $643M market cap in the same report. Do not reintroduce an unfiltered
// pair list here.
let total: f64 = round2(pairs.iter().map(liq).sum());
let top = pairs.first();
let fdv = top.and_then(|p| p.fdv.or(p.market_cap));
let liq_to_fdv = fdv.filter(|f| *f > 0.0).map(|f| round2(total / f * 100.0));
let has_socials = top
.and_then(|p| p.info.as_ref())
.map(|i| !i.socials.is_empty() || !i.websites.is_empty())
.unwrap_or(false);
if pairs.is_empty() {
flags.push(
Flag::new(
"no_liquidity",
Severity::Danger,
"No DEX liquidity found",
// DexScreener indexing lags new pools by minutes and does not
// cover every venue. "Not indexed" is an observation about an
// index; "cannot be bought or sold" is a claim about the chain,
// and there is no on-chain pool probe here to back it.
"No tradable pair is INDEXED for this mint. Either no pool exists, or the pool is too new / on a venue DexScreener doesn't cover — Solwatch cannot tell those apart, so verify on-chain before concluding the token is untradable.".into(),
25,
)
.hard(),
);
} else {
let depth_reported = pairs
.iter()
.any(|p| p.liquidity.as_ref().and_then(|l| l.usd).is_some());
if !depth_reported {
// DexScreener indexes the pair but reports no pool depth — typical
// for bonding-curve venues. "Unreported" is not "zero"; say so.
flags.push(Flag::new(
"liquidity_unreported",
Severity::Info,
"Pool depth not reported",
"DexScreener doesn't publish liquidity for this venue (bonding curve) — assume it is tiny.".into(),
3,
));
} else if total < 5000.0 {
flags.push(Flag::new(
"low_liquidity",
Severity::Danger,
"Very low liquidity",
format!(
"Only ${} of total liquidity — the pool can be drained or the price wrecked with pocket change.",
fmt(total)
),
20,
));
} else if total < 25000.0 {
flags.push(Flag::new(
"low_liquidity",
Severity::Warning,
"Low liquidity",
format!(
"${} total liquidity — exits get expensive fast.",
fmt(total)
),
8,
));
}
if let Some(r) = liq_to_fdv {
// Only meaningful for thin tokens — large caps keep most of their
// depth on CEXes, and unreported (bonding-curve) depth reads as 0.
if depth_reported && r < 2.0 && total < 150_000.0 {
flags.push(Flag::new(
"liq_fdv_ratio",
Severity::Warning,
"Liquidity tiny vs market cap",
format!("Liquidity is only {r}% of the market cap — the price is mostly on paper and exit is hard."),
10,
));
}
}
// Token trading age = the OLDEST pair. Trending tokens accrete fresh
// pools constantly (arb/DLMM LPs), so the youngest pair says nothing
// about the token's age — keying on it called a day-old token
// "~0h old" (observed live on a token with a 1h-old Meteora pool).
let oldest = pairs
.iter()
.filter_map(|p| p.pair_created_at)
.map(|c| (now_ms - c) / 3_600_000)
.max();
if let Some(h) = oldest {
if h < 6 {
flags.push(Flag::new(
"very_new",
Severity::Warning,
"Brand-new token",
format!("The oldest trading pair is ~{h}h old — most rugs happen in the first hours."),
6,
));
}
}
if !has_socials {
flags.push(Flag::new(
"no_socials",
Severity::Info,
"No socials listed",
"No website/X/Telegram on the DexScreener profile.".into(),
3,
));
}
// Sell-pressure read from the BUSIEST pair's 24h txns — the deepest
// pool is often not where the trading is on migrated tokens.
let busiest = pairs
.iter()
.max_by(|a, b| {
(a.volume.h24.unwrap_or(0.0))
.partial_cmp(&b.volume.h24.unwrap_or(0.0))
.unwrap_or(std::cmp::Ordering::Equal)
})
.or(top);
if let Some(p) = busiest {
let (b, s) = (p.txns.h24.buys, p.txns.h24.sells);
if b + s >= 50 && s > 0 && b as f64 / s as f64 > 5.0 {
flags.push(Flag::new(
"buy_sell_imbalance",
Severity::Warning,
"Buys massively outnumber sells",
format!("{b} buys vs {s} sells in 24h — either nobody CAN sell (test a tiny sell first) or bots are painting volume."),
8,
));
}
}
}
// Token-level 24h volume: every base-side pair PLUS pairs where this mint
// is the QUOTE token. The `pairs` array below is truncated to 8 for display
// and sorted by liquidity, so summing volume out of it drops exactly the
// thin-but-busy pools where trading actually happens; and ignoring
// quote-side pairs understated tokens that mostly trade as a quote (PYUSD
// read $12k against a real ~$1.2M — a 99% miss).
let total_volume_24h: f64 =
pairs.iter().filter_map(|p| p.volume.h24).sum::<f64>() + quote_side_volume;
let section = json!({
"totalLiquidityUsd": total,
"totalVolume24hUsd": total_volume_24h,
"quoteSideVolume24hUsd": quote_side_volume,
// Epoch ms of the OLDEST pair = when this token actually started
// trading. Published because Jupiter's `created_at` is its own INDEX
// row date, not the token's: it dated BONK (Dec 2022), WIF (Nov 2023),
// JUP (Jan 2024) and PYUSD all to the same 2026-06-07, and PYUSD's
// "creation" landed BEFORE its own first pool — impossible.
"firstPairCreatedAtMs": pairs.iter().filter_map(|p| p.pair_created_at).min(),
// Disclosed so a filtered read is never passed off as the raw feed.
"droppedMispricedPairs": dropped_mispriced,
"pairCount": pairs.len(),
"fdvUsd": fdv,
"liqToFdvPct": liq_to_fdv,
"hasSocials": has_socials,
"pairsTruncated": pairs.len() > 8,
"pairs": pairs.iter().take(8).map(|p| json!({
"dex": p.dex_id,
"labels": p.labels,
"pairAddress": p.pair_address,
"quoteSymbol": p.quote_token.symbol,
"liquidityUsd": liq(p),
"priceUsd": p.price_usd.as_ref().and_then(|s| s.parse::<f64>().ok()),
"ageHours": p.pair_created_at.map(|c| (now_ms - c) / 3_600_000),
"txns24h": {"buys": p.txns.h24.buys, "sells": p.txns.h24.sells},
"txns1h": {"buys": p.txns.h1.buys, "sells": p.txns.h1.sells},
"priceChange": {"m5": p.price_change.m5, "h1": p.price_change.h1, "h6": p.price_change.h6, "h24": p.price_change.h24},
"volume": {"m5": p.volume.m5, "h1": p.volume.h1, "h6": p.volume.h6, "h24": p.volume.h24},
})).collect::<Vec<_>>(),
});
LiquidityAnalysis {
pool_addresses: pairs.iter().map(|p| p.pair_address.clone()).collect(),
total_liquidity_usd: total,
pair_count: pairs.len(),
// The DEEPEST pool, not whichever pair the API happened to list first.
// `audit.rs` turns this into an LP-safety posture — including the
// PumpSwap "liquidity is protocol-owned and cannot be pulled by the dev"
// guarantee — so electing an arbitrary first pair could publish that
// assurance about a token whose majority liquidity sits in a separate,
// fully dev-owned pool.
top_dex: pairs
.iter()
.max_by(|a, b| {
liq(a)
.partial_cmp(&liq(b))
.unwrap_or(std::cmp::Ordering::Equal)
})
.map(|p| p.dex_id.clone()),
flags,
section,
fetch_error: None,
}
}
fn fmt(n: f64) -> String {
let mut s = String::new();
let int = n.round() as i64;
let digits = int.abs().to_string();
for (i, c) in digits.chars().enumerate() {
if i > 0 && (digits.len() - i) % 3 == 0 {
s.push(',');
}
s.push(c);
}
s
}