SPB Git

Repository Public

enabled.ts 1.7 KB 26 lines typescript

1// Which adapters actually run. The registry (providers/index.ts) lists every adapter that exists; this file applies the2// owner's terms-of-use decisions on top, so that an adapter being present in the code never means it is being used.3import { createProviders, type ProviderEnv } from './providers/index.ts';4import type { SwapProvider } from './types.ts';56/**7 * Off unless explicitly enabled:8 *  - debridge: its API licence (SDK & API License Agreement, 1 Oct 2025) says "The APIs shall not be used for aggregation9 *    purposes". A multi-provider router is arguably that. Enable only after the owner has reviewed it or obtained approval10 *    (SPW_SWAP_ENABLE=debridge).11 */12const OFF_BY_DEFAULT = new Set(['debridge']);13const POLICY: Record<string, SwapProvider['policy']> = {14  // keyless LI.FI allows 75 route requests per 2 hours per IP: spend them slowly; a key lifts this (LIFI_API_KEY)15  lifi: { ratePerSec: 0.01, burst: 6, timeoutMs: 3500, scarce: true },16  debridge: { timeoutMs: 4500 },17  // the only keyless THORNode gateway answers in 2–5 s and is sometimes stale: give it time rather than report a timeout18  thorchain: { timeoutMs: 6500, ratePerSec: 0.5, burst: 4 },19};20export function createEnabledProviders(env: ProviderEnv = {}): SwapProvider[] {21  const on = new Set((env.SPW_SWAP_ENABLE ?? '').split(',').map((s) => s.trim()).filter(Boolean));22  const off = new Set((env.SPW_SWAP_DISABLE ?? '').split(',').map((s) => s.trim()).filter(Boolean));23  return createProviders(env).filter((p) => !off.has(p.id) && (!OFF_BY_DEFAULT.has(p.id) || on.has(p.id)))24    .map((p) => { const extra = p.id === 'lifi' && env.LIFI_API_KEY ? undefined : POLICY[p.id]; return extra ? Object.assign(p, { policy: { ...extra, ...p.policy } }) : p; });25}26
Files main
Menu

Theme