Skip to content

fix(protocol): validate constants response with Zod schema (#1979) - #2004

Draft
s6pa1rta3n-lab wants to merge 1 commit into
Commitlabs-Org:masterfrom
s6pa1rta3n-lab:fix-issue-1979
Draft

s6pa1rta3n-lab wants to merge 1 commit into
Commitlabs-Org:masterfrom
s6pa1rta3n-lab:fix-issue-1979

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Summary

Fixes #1979 by adding runtime Zod schema validation to fetchProtocolConstants in src/utils/protocol.ts.

Previously, fetchProtocolConstants accepted raw JSON without validating the payload structure against the ProtocolConstants type contract. An incomplete backend response (such as missing commitmentLimits.earlyExitGracePeriodDays) would silently return an object with undefined properties.

Changes

  • Updated src/lib/schemas/apiContracts.ts to export inferred ProtocolConstants and ProtocolConstantsResponse types.
  • Implemented fetchProtocolConstants in src/utils/protocol.ts validating API responses against ProtocolConstantsResponseSchema (with transparent handling for both enveloped and direct constants payloads).
  • Added explicit rejection throwing a detailed error message if schema parsing fails.
  • Preserved domain helper getEarlyExitGracePeriodDays with defensive bounds checking.
  • Added comprehensive unit tests in src/utils/__tests__/protocol.test.ts and src/utils/tests/protocol.test.ts asserting:
    • Enveloped payload parsing ({ success: true, data: ... }).
    • Direct payload parsing.
    • Custom endpoint forwarding.
    • HTTP failure reporting (statusText).
    • Missing field rejections (e.g. missing earlyExitGracePeriodDays).
    • Malformed field type rejections.
    • Normalization in getEarlyExitGracePeriodDays.

Acceptance Criteria Checklist

  • Runtime Zod schema defined and exported for /api/protocol/constants response.
  • fetchProtocolConstants validates parsed JSON against the Zod schema.
  • Malformed or missing fields (e.g., commitmentLimits.earlyExitGracePeriodDays) throw clear validation errors.
  • Unit test asserting malformed responses reject with diagnostic error messages.
  • 100% test coverage on src/utils/protocol.ts.

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

@vercel

vercel Bot commented Sep 29, 2026

Copy link
Copy Markdown

@s6pa1rta3n-lab is attempting to deploy a commit to the 1nonly's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetchProtocolConstants in src/utils/protocol.ts trusts the raw JSON response with no runtime validation

1 participant