Skip to content

feat(refund_ratio_helper): ticker fallbacks, DB precision rows, CSV export, rate limit - #591

Merged
godamongstmen897 merged 1 commit into
Goldii-locks:mainfrom
nevysonzim124:feat/469-470-471-472-refund-ratio-helper
Sep 28, 2026
Merged

godamongstmen897 merged 1 commit into
Goldii-locks:mainfrom
nevysonzim124:feat/469-470-471-472-refund-ratio-helper

Conversation

@nevysonzim124

Copy link
Copy Markdown
Contributor

Summary

Adds four features to refund_ratio_helper, the dispute refund percentage splitter.

  • Handle unknown asset ticker keys on refund_ratio_helper #469: Unknown asset tickers. resolveRefundAssetTicker / getRefundAssetFormatConfig look up a registry of known assets (XLM, USDC, EURC, USDT). If a ticker is missing, malformed (not 1–12 alphanumeric characters), or unregistered, DEFAULT_REFUND_ASSET_CONFIG (7 decimals) is used. An unknown ticker that is well formed keeps its upper-cased name so rows can still be traced to it. Prototype keys like constructor never resolve.
  • Configure format columns for DB storage in refund_ratio_helper #470: DB precision formatting. formatRefundRowForDb({ amount, ratio, ticker }) computes the refund and the remaining share. It writes each amount as a TEXT column with exactly decimals fractional digits, plus the exact raw integer values. Before returning the row, it parses every formatted value back and checks it matches the raw value. REFUND_DB_COLUMN_SCHEMAS declares the column formats.
  • Write format exporters inside the refund_ratio_helper module #472: CSV exporters. buildRefundCsvBlock produces a header line plus one line per row, escaped with the existing escapeCSVField. writeRefundCsvFile writes that block to disk, creating directories as needed. An empty table is refused.
  • Add rate limiting checks on refund_ratio_helper calls #471: Rate limiting. New refundRatioRateLimit middleware follows the existing per-path limiter pattern. Limits are set by REFUND_RATIO_RATE_MAX (default 20) and REFUND_RATIO_RATE_WINDOW_MS (default 60000). Over the limit, it returns 429 with a Retry-After header and logs a warning.

The existing applyRefundRatio / validation behavior is unchanged. The only other change: the internal failure helpers now return the narrower ValidationFailure type.

Tests

  • __tests__/refund_ratio_helper_formatting.test.ts:
    • default config applied for missing, malformed, and unknown tickers
    • written row attributes round-trip at full precision, including the 15-digit maximum
    • exported CSV files contain the correct table
  • __tests__/refund-ratio-rate-limit.test.ts:
    • 429 plus a warning once the threshold is exceeded
    • clients tracked separately, and the limit resets after the window
    • other routes are not throttled
    • invalid env values fall back to the defaults

npm test: 131 suites, 2854 tests, all passing. tsc -p tsconfig.build.json --noEmit is clean.

Closes #469
Closes #470
Closes #471
Closes #472

🤖 Generated with Claude Code

…xport, rate limit

- Goldii-locks#469: resolve asset ticker keys against a known-asset registry and apply
  DEFAULT_REFUND_ASSET_CONFIG (7 decimals) to missing/malformed/unknown tickers
- Goldii-locks#470: formatRefundRowForDb renders amount/refund/remaining as fixed-precision
  TEXT columns and verifies each round-trips to its raw bigint value
- Goldii-locks#472: buildRefundCsvBlock / writeRefundCsvFile export formatted rows as CSV
- Goldii-locks#471: refundRatioRateLimit middleware returns 429 with Retry-After and a
  logged warning once REFUND_RATIO_RATE_MAX is exceeded per window

Closes Goldii-locks#469, closes Goldii-locks#470, closes Goldii-locks#471, closes Goldii-locks#472

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@nevysonzim124 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@godamongstmen897
godamongstmen897 merged commit a2041b4 into Goldii-locks:main Sep 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants