Repository navigation
feat(pricing): add staleness-aware median pricing with priority source fallback (#81) - #628
Open
phatloi0010 wants to merge 1 commit into
Open
phatloi0010 wants to merge 1 commit into
phatloi0010 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements staleness-aware median pricing across multiple price sources with priority fallback chain and source inclusion/exclusion annotations.
Closes #81
Changes
src/pricing/median.ts:calculateMedian(returningnumber | null, never0on empty input),clampFreshnessThreshold(bounded to[5, 86400]seconds, default300s),computeStalenessAwareMedian, andgetStalenessAwareMedianPrice.freshnessThresholdSeconds(recording them inexcludedSourceswithreason: 'stale'andageSeconds) as well as non-positive/non-finite quotes (reason: 'invalid_price' | 'invalid_timestamp').['SDEX', 'AMM', 'SOROSWAP', 'PHOENIX', 'AQUARIUS', 'REFLECTOR', 'DEFINDEX'], falling back to the freshest valid stale source when none match the priority list) when all valid sources are stale, annotatingfallbackUsed: true,fallbackSource, andfallbackAgeSeconds.reason: 'no_price_data') from all-invalid input (reason: 'all_sources_invalid'), returningmedianPrice: nullin both cases.src/api/rest.ts,openapi.yaml,openapi.json,README.md,docs/what-lens-knows.md,clients/typescript/src/schema.d.ts:GET /price/:assetA/:assetB/median(and/v1/price/{assetA}/{assetB}/medianin OpenAPI + generated artifacts) withfreshnessvalidation in[5, 86400]seconds (HTTP400when out of bounds) and HTTP404whenmedianPrice === null.src/__tests__/medianPricing.test.ts:fallbackAgeSeconds, freshness parameter bounds, and database/REST integration.Verification
npx tsc --noEmit: PASS (0errors)npm run client:typecheck&npm run readme:check: PASSnpx vitest run src/__tests__/medianPricing.test.ts tests/openapi.test.ts tests/readme.test.ts tests/rest-route.test.ts: PASS (4/4files,94/94tests)node scripts/check-dropped-tests.mjs origin/main HEAD: PASS (0dropped test cases)