Skip to content

feat(scripting): add zod schemas and viem transform helpers#690

Open
yahgwai wants to merge 3 commits intomainfrom
feat/zod-schema
Open

feat(scripting): add zod schemas and viem transform helpers#690
yahgwai wants to merge 3 commits intomainfrom
feat/zod-schema

Conversation

@yahgwai
Copy link
Copy Markdown
Contributor

@yahgwai yahgwai commented Apr 8, 2026

no-issue

All together on: #686

Summary

Adds zod schemas and transforms for every SDK function that takes RPC/client input. Schemas validate JSON input and transforms convert it to SDK-ready arguments -- RPC URLs become viem clients, private keys become accounts, strings become bigints. The target audience here is devs who are already familiar with zod, and helping them to write scripts without messing up the arg parsing, and letting them follow a opinionated structure. Devs who arent familiar with zod dont get benefit here, but it's not a complicated library to learn, and I think it's a useful thing to know about.

WARNING: we're creating schemas for every function, so there's a lot of code being added here, but two things are worth focusing on which help us to gain confidence in the correctness of the code:

  • The schema type tests - here we're trying to test that the output of the transformed schema could be directly into its equivalent sdk function, so if you're confident those tests work then in theory the schemas are good from a correctness point of view
  • In all cases where we can we set the return type of the schema transform to Parameters

Not included for now

  • Additional parsing libs. Now that we have zod schemas which will parse json, we can use existing tooling to convert yaml, env vars or cli args to json and than parse with the same schema giving scripts more options of what they expose to users.
  • Describe() - we can add documentation to the schemas to give consumers and idea of what values to put into the params. Those descriptions can be accessed via a dry-run/help command or zod can be converted into json schemas to directly expose the documentation.
  • Documentation and readme. Three sets of documentation is required: one for sdk maintainers, one for script writers and one for users of the cli.
  • Extending the CLI with some standard useful scripts to be used by SRE/other consumers

Add zod v4 validation schemas and transform functions for all SDK
operations. Includes shared primitives (address, hex, bigint schemas),
per-function schema/transform pairs, and viem client factory helpers.
Abitype's peer dep on zod ^3 caused pnpm to keep zod@3.22.4 in the tree,
creating non-portable abitype resolution paths that TypeScript couldn't
name in .d.ts output.
@yahgwai yahgwai reopened this Apr 8, 2026
@yahgwai yahgwai requested a review from spsjvc April 8, 2026 14:32
Rename gasOverrideOptionsSchema -> gasOptionsSchema,
gasOverridesSchema -> gasLimitSchema,
retryableGasOverridesSchema -> tokenBridgeRetryableGasOverridesSchema.

Reorder hexSchema and privateKeySchema in common.ts.

Use destructuring + spread in 9 transforms to reduce repetitive
input field assignments.
@yahgwai yahgwai requested a review from douglance April 8, 2026 15:55
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.

1 participant