Skip to content

Commit 6fb8f8b

Browse files
committed
feat(discovery): auto-seed Lista/Wombat candidates from protocol metadata
1 parent 38c2d77 commit 6fb8f8b

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

apps/dashboard/server.mjs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9324,6 +9324,14 @@ function parseAddressCandidates(raw) {
93249324
.filter((x) => /^0x[a-fA-F0-9]{40}$/.test(x));
93259325
}
93269326

9327+
async function readWithFallback(callFn, fallback = null) {
9328+
try {
9329+
return await callFn();
9330+
} catch {
9331+
return fallback;
9332+
}
9333+
}
9334+
93279335
function parseUrlCandidates(raw) {
93289336
return String(raw || "")
93299337
.split(/[\n,;]+/)
@@ -9413,6 +9421,28 @@ async function discoverPoolCandidatesFromDefiLlama(protocol) {
94139421
}
94149422
}
94159423

9424+
async function discoverSeedCandidatesFromProtocolMeta(protocol) {
9425+
const key = String(protocol || "").toLowerCase();
9426+
const out = [];
9427+
if (key === "wombat") {
9428+
out.push(
9429+
"0xad6742a35fb341a9cc6ad674738dd8da98b94fb1",
9430+
"0x489833311676b566f888119c29bd997dc6c95830",
9431+
);
9432+
}
9433+
try {
9434+
const protocolSlug = key === "lista" ? "lista-dao" : "wombat-exchange";
9435+
const payload = await fetchJsonWithTimeout(
9436+
`https://api.llama.fi/protocol/${protocolSlug}`,
9437+
);
9438+
const extracted = extractEvmAddressesFromJson(payload || {});
9439+
for (const addr of extracted) out.push(addr);
9440+
} catch {
9441+
// ignore
9442+
}
9443+
return [...new Set(out)];
9444+
}
9445+
94169446
async function scorePoolCandidates(candidates) {
94179447
const provider = new JsonRpcProvider(BSC_RPC_URL, {
94189448
name: "bsc",
@@ -9455,16 +9485,26 @@ async function discoverBscPoolsByProtocol(protocol) {
94559485
candidates = await discoverPoolCandidatesFromDefiLlama(key);
94569486
source = "defillama";
94579487
}
9488+
if (candidates.length === 0) {
9489+
candidates = await discoverSeedCandidatesFromProtocolMeta(key);
9490+
source = "protocol-meta-seed";
9491+
}
94589492
if (candidates.length === 0) {
94599493
warning =
9460-
"auto-discovery found no BSC pool addresses from configured protocol API URLs or DeFiLlama; set BSC_*_POOL_DISCOVERY_API_URLS or BSC_*_POOL_CANDIDATES";
9494+
"auto-discovery found no BSC pool addresses from configured protocol API URLs / DeFiLlama / protocol metadata; set BSC_*_POOL_DISCOVERY_API_URLS or BSC_*_POOL_CANDIDATES";
94619495
}
94629496
const rows = await scorePoolCandidates(candidates);
9497+
const topScore = Number(rows[0]?.liquidityScore || 0);
9498+
const recommended = topScore > 0 ? (rows[0]?.pool ?? null) : null;
9499+
if (!warning && rows.length > 0 && topScore <= 0) {
9500+
warning =
9501+
"auto-discovery candidates found but liquidity score is zero; recommendation withheld for safety";
9502+
}
94639503
return {
94649504
protocol: key,
94659505
source,
94669506
candidates: rows,
9467-
recommended: rows[0]?.pool || null,
9507+
recommended,
94689508
warning,
94699509
};
94709510
}

0 commit comments

Comments
 (0)