Skip to content

Adopt branded zod schemas across lend/swap/wallet controllers #475

Description

@its-everdred

PR #465 introduced shared branded zod helpers in packages/demo/backend/src/helpers/schemas.ts:

  • AddressSchema — validates 0x[a-fA-F0-9]{40} and lowercases the value before branding as Address.
  • Bytes32Schema — validates and lowercases bytes32.
  • ChainIdSchema / ChainIdStringSchema — accepts number or numeric string, brands as SupportedChainId.
  • BorrowAmountRawSchema — bigint-as-decimal-string capped at .max(78) to bound DoS surface.

These live in helpers/schemas.ts so lend/swap/wallet can share them. Today only borrow consumes them; the rest still use raw regex or ad-hoc transforms:

  • controllers/wallet.ts:32 (/wallet/eth/...) — raw regex on address, no lowercase normalization.
  • controllers/lend.ts — request shapes use bespoke validators.
  • controllers/swap.ts — request shapes use bespoke validators.

Acceptance

  • Replace ad-hoc address validation in controllers/wallet.ts, controllers/lend.ts, controllers/swap.ts with AddressSchema from helpers/schemas.ts.
  • Replace ad-hoc chainId parsing with ChainIdSchema / ChainIdStringSchema where appropriate.
  • Apply BorrowAmountRawSchema (or a renamed AmountRawSchema) to lend/swap amount fields if currently uncapped strings.
  • If we rename for breadth, update borrow consumers in the same PR.
  • Add tests confirming mixed-case input is normalized at the boundary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:todoFollow-up task suitable for agent implementation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions