Flash unwinder contracts and scripts, relay lane tuning, trustless bridge and token-aggregation updates.

Made-with: Cursor
This commit is contained in:
defiQUG
2026-04-12 06:33:54 -07:00
parent 662b35ad69
commit 6817f53591
40 changed files with 682 additions and 88 deletions

View File

@@ -8,6 +8,17 @@ interface CacheEntry {
const cache = new Map<string, CacheEntry>();
const DEFAULT_TTL = 60 * 1000; // 1 minute
/** Never cache generic API error envelopes (avoids poisoning cache if status/body ever disagree). */
function looksLikeGenericErrorPayload(body: unknown): boolean {
if (body == null || typeof body !== 'object' || Array.isArray(body)) return false;
const o = body as Record<string, unknown>;
if (typeof o.error !== 'string') return false;
// Success shapes we must not treat as errors
if ('pools' in o || 'tokens' in o || 'data' in o || 'chains' in o || 'tree' in o || 'quote' in o) return false;
if (o.status === 'healthy') return false;
return true;
}
export function cacheMiddleware(ttl: number = DEFAULT_TTL) {
return (req: Request, res: Response, next: NextFunction) => {
const bypassCache =
@@ -29,7 +40,9 @@ export function cacheMiddleware(ttl: number = DEFAULT_TTL) {
// Override json method to cache response
res.json = function (body: unknown) {
if (!bypassCache) {
// Only cache successful payloads. Otherwise a 500 body gets replayed on cache hit with HTTP 200.
const okStatus = res.statusCode >= 200 && res.statusCode < 300;
if (!bypassCache && okStatus && !looksLikeGenericErrorPayload(body)) {
cache.set(key, {
data: body,
expiresAt: Date.now() + ttl,