ethereum-optimism / ethereum-optimism/actions

Adopt branded zod schemas across lend/swap/wallet controllers

Open
#475 0 comments 0 reactions 0 assignees View on GitHub
agent:todo
Dominant language
TypeScript
Stars
32
Forks
26
Avg merge
10h 20m
Merged PRs (30d)
16

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start in packages/demo/backend/src/helpers/schemas.ts, then compare the existing borrow consumers with controllers/wallet.ts, controllers/lend.ts, and controllers/swap.ts. Trace each controller's request shapes and current validators, then add or update tests for mixed-case normalization and bounded amounts; done means all listed controllers use the shared schemas consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.