Fix/rate limit pools swaps dto normalize#463
Open
james2177 wants to merge 4 commits into
Open
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
Related issue
Closes #373
closes #374
closes #375
closes #376
What was implemented
Issue 1 — Rate limit POST /transactions
File: rate-limit/rate-limit.middleware.ts
Added a specific sliding-window rule for POST /transactions in endpointRuleFor(): 20 req/min for public callers, 120 req/min for internal. The routeBucketFor() method now buckets /transactions separately so its Redis key is isolated from the global counter. Two new env vars control the limits: TRANSACTION_RATE_LIMIT_PER_MINUTE and INTERNAL_TRANSACTION_RATE_LIMIT_PER_MINUTE. Two tests were added verifying the X-RateLimit-Limit: 20 header is applied to POST but not GET on that path.
Issue 2 — GET /pools filter by token pair
Files: pools/dto/get-pools-query.dto.ts, pools/pool.types.ts, pools/pools.repository.ts, pools/pools.service.ts
Added optional token0 and token1 query params. When both are supplied the repository performs a bidirectional exact-pair match ((t0=A AND t1=B) OR (t0=B AND t1=A)). When only one is supplied it matches either position. These coexist with the existing search param. The service passes them through and includes them in the cache key to isolate pair-filtered results. Two unit tests added.
Issue 3 — GET /swaps pagination by pool
Files: swaps/dto/get-swaps-query.dto.ts, swaps/swap.types.ts, swaps/swaps.repository.ts, swaps/swaps.service.ts, swaps/swaps.controller.ts
Renamed the ambiguous pool query param to poolId throughout the DTO, internal SwapsQuery type, and repository so the intent is unambiguous. Added @apitags('Swaps'), @apioperation, and @apiresponse to SwapsController so the endpoint is fully documented in Swagger. Tests updated to use poolId.
Issue 4 — Normalize DTO field names tokenPair
Files: swaps/swaps.service.ts, swaps/swaps.service.spec.ts
Added a tokenPair: string field to SwapResponse computed as "TOKEN0SYMBOL/TOKEN1SYMBOL" (e.g. "USDC/XLM"). The existing token0Symbol/token1Symbol fields are kept for backward compatibility. A dedicated test asserts the field is present and correctly formatted.
Type of change
Checklist