Skip to content

feat: generate TypeScript contract bindings with CI sync check#530

Merged
sanmipaul merged 4 commits into
astera-hq:mainfrom
distributed-nerd:feat/contract-typescript-bindings
May 30, 2026
Merged

feat: generate TypeScript contract bindings with CI sync check#530
sanmipaul merged 4 commits into
astera-hq:mainfrom
distributed-nerd:feat/contract-typescript-bindings

Conversation

@distributed-nerd
Copy link
Copy Markdown

Closes #427

Summary

Adds automated TypeScript binding generation from the Soroban contract ABI so SDK authors and frontend developers no longer have to read the Rust source to understand the API, and so the bindings can't silently go stale.

Changes

  • scripts/gen-bindings.sh — builds each contract to WASM and runs stellar contract bindings typescript, writing the generated module to frontend/src/generated/<contract>.ts. Defaults to all contracts; accepts a subset as args.
  • Generated bindings committed under frontend/src/generated/ (invoice.ts, credit_score.ts) plus a namespaced index.ts barrel. Excluded from ESLint/Prettier so they stay byte-for-byte identical to the tool output.
  • CI — new generate-bindings job in .github/workflows/contracts.yml installs a pinned stellar-cli (22.6.0), regenerates the bindings, and runs git diff --exit-code frontend/src/generated/, failing CI if the committed bindings drift from the contract source.
  • frontend/lib/contracts.ts — now imports the generated Errors maps, re-exports the generated contract clients and raw ABI types (InvoiceAbi/InvoiceStatusAbi/InvoiceMetadataAbi), and adds getContractErrorByCode() resolving numeric contract error codes to friendly messages using the generated bindings as the source of truth.
  • CONTRIBUTING.md — new "Regenerating Contract Bindings" section documenting when/how to regenerate, the pinned CLI version, the CI sync check, and the pool caveat below.

Acceptance criteria

  • stellar contract bindings typescript step added to CI
  • Generated bindings committed to frontend/src/generated/
  • CI fails if bindings are stale (git diff --exit-code)
  • contracts.ts updated to import from generated bindings
  • CONTRIBUTING.md documents how to regenerate bindings locally

Notes

  • CLI form: the modern stellar CLI (22.6.0) emits a package directory via --output-dir rather than the single --output …invoice.ts file shown in the issue (that was the older soroban CLI). The script bridges this by copying the generated src/index.ts into the exact frontend/src/generated/<contract>.ts layout the issue specifies.
  • pool is intentionally excluded for now. The pool contract currently does not compile: its PoolError enum has 52 variants, but Soroban caps contract-spec error enums at 50 (VecM<ScSpecUdtErrorEnumCaseV0, 50>), so #[contracterror] panics with LengthExceedsMax and no WASM/spec can be produced. This is a pre-existing build failure unrelated to bindings and deserves its own fix. pool is already wired into scripts/gen-bindings.sh and documented, so re-enabling it is a one-line change once the contract builds.

Testing

  • ./scripts/gen-bindings.sh invoice credit_score is deterministic — re-running produces no git diff (the CI sync check passes).
  • npm run lint passes (0 errors); generated files are correctly ignored.
  • Confirmed the change introduces no new tsc errors (pre-existing errors on main are in unrelated files).

shaaibu7 added 4 commits May 28, 2026 21:12
Add scripts/gen-bindings.sh, which builds each contract to WASM and runs
`stellar contract bindings typescript` to produce TypeScript clients/types,
writing them to frontend/src/generated/<contract>.ts. Commit the generated
bindings for invoice and credit_score plus a namespaced barrel, and exclude
the generated directory from ESLint/Prettier.

pool is wired into the script by default but not generated yet: its PoolError
enum exceeds Soroban's 50-case contract-spec limit, so the contract does not
compile. Re-enable it once that build is fixed.
…ed bindings

contracts.ts now imports the generated Errors maps and re-exports the generated
contract clients and raw ABI types (Invoice/InvoiceStatus/InvoiceMetadata).
Adds getContractErrorByCode(), which resolves a numeric contract error code to a
friendly message using the generated bindings as the source of truth, so the
error catalogue tracks the contract source automatically.
Add a generate-bindings job to the Soroban contracts workflow that installs a
pinned stellar-cli (22.6.0), regenerates the TypeScript bindings via
scripts/gen-bindings.sh, and runs `git diff --exit-code frontend/src/generated/`
so CI fails if the committed bindings drift from the contract source. pool is
omitted from the regeneration list until its build is fixed.
Add a 'Regenerating Contract Bindings' section covering when/how to regenerate,
the pinned stellar-cli version, the CI sync check, and the pool build caveat.
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@distributed-nerd 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

@sanmipaul sanmipaul merged commit 65f696d into astera-hq:main May 30, 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

Development

Successfully merging this pull request may close these issues.

feat: add contract ABI documentation generator to CI

3 participants