Skip to content

perf: wasm intent layer - #98

Open
conwayconstar wants to merge 3 commits into
mainfrom
perf/wasm-intent-layer
Open

perf: wasm intent layer#98
conwayconstar wants to merge 3 commits into
mainfrom
perf/wasm-intent-layer

Conversation

@conwayconstar

@conwayconstar conwayconstar commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

What

Adds startup-safe SDK subpaths so web startup code can import lightweight call/topic/error/primitive helpers without pulling in the full wasm-bindgen runtime:

  • @bulletxyz/sdk-wasm/calls
  • @bulletxyz/sdk-wasm/topics
  • @bulletxyz/sdk-wasm/errors
  • @bulletxyz/sdk-wasm/primitives

The new /calls entrypoint emits plain runtime-call data. The full WASM runtime is only crossed when the app explicitly converts or submits that data:

  • RuntimeCall.fromCall(call)
  • Transaction.builder().call(RuntimeCall.fromCall(call))
  • client.sendCall(call)

Existing root APIs remain supported, including CallMessage, User.*, .callMessage(...), and client.sendCallMessage(...).

Why

The web app was paying for the full SDK/WASM runtime during initial route startup because importing factories, enums, topics, and error helpers from the root package pulled generated wasm-bindgen glue into the startup graph.

This lets /trade and other startup paths define transaction callbacks, topic strings, enum values, and error guards without importing the WASM runtime. The app only pays for WASM when it initializes the client or actually builds/signs/submits a transaction.


Note

Medium Risk
New public package surface and transaction submission path (fromCall / sendCall) must stay aligned with schema serde and existing signing; mistakes could affect submitted call payloads, though existing APIs remain and tests cover the boundary.

Overview
Adds startup-safe WASM SDK subpaths so route-level code can import call builders, topics, primitives, and error guards without pulling in wasm-bindgen glue or the .wasm binary.

Codegen in wasm/build.rs now writes wasm/.generated/ (gitignored) and just build-wasm copies those bundles into pkg/. package.json exports ./calls, ./topics, ./errors, and ./primitives. Schema-driven emitters produce plain RuntimeCallData (exchange actions from the schema, plus JS Warp.transferRemote with safe-integer amount checks), frozen enums/structs, websocket Topic helpers, and isBulletSdkError / asBulletSdkError.

Bridges intent data into the full runtime via RuntimeCall.fromCall(call) (serde first, warp fallback through existing Warp::transfer_remote), Transaction.builder().call(...), and client.sendCall(call). Root APIs (User.*, .callMessage, sendCallMessage) are unchanged.

Docs cover the lazy-import pattern; Jest tests assert subpaths avoid WASM imports and round-trip through RuntimeCall.fromCall.

Reviewed by Cursor Bugbot for commit e452fb2. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Adds a startup-safe WASM intent layer for the web by exposing lightweight SDK subpaths that don’t load the wasm-bindgen runtime. Apps can build calls, topics, primitives, and error guards at route startup and only cross the WASM boundary when converting or submitting.

  • New Features

    • New side-effect-free subpaths: @bulletxyz/sdk-wasm/calls, @bulletxyz/sdk-wasm/topics, @bulletxyz/sdk-wasm/errors, @bulletxyz/sdk-wasm/primitives.
    • Call builders return plain runtime-call data with isRuntimeCallData and toRuntimeCallJson; convert/submit via RuntimeCall.fromCall(call), Transaction.builder().call(...), and client.sendCall(call).
    • Added Warp.transferRemote(...) with strict amount handling (string/bigint/safe integer) and relayer normalization.
    • Startup-safe topics and primitives: Topic.*, OrderbookDepth, KlineInterval, enums, and struct classes with toJSON().
    • Errors helpers: isBulletSdkError and asBulletSdkError available from @bulletxyz/sdk-wasm/errors. Docs updated; codegen emits subpath bundles and an internal startup-shared (not exported). Tests lock that these imports don’t pull wasm/glue.
  • Migration

    • No breaking changes; existing root imports like User.*, CallMessage, and client.sendCallMessage(...) still work.
    • For React or other startup paths, import from the new subpaths to avoid loading the WASM runtime until needed.

Written for commit e452fb2. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread wasm/codegen/bullet_schema/emit/startup_subpaths.rs Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 11 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="wasm/codegen/bullet_schema/emit/startup_subpaths/calls.rs">

<violation number="1" location="wasm/codegen/bullet_schema/emit/startup_subpaths/calls.rs:121">
P2: Warp amount normalization accepts any string without integer validation. Invalid amount strings bypass startup checks and fail later when converting to runtime calls.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

return String(value);
}
if (typeof value === "string") {
return value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Warp amount normalization accepts any string without integer validation. Invalid amount strings bypass startup checks and fail later when converting to runtime calls.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At wasm/codegen/bullet_schema/emit/startup_subpaths/calls.rs, line 121:

<comment>Warp amount normalization accepts any string without integer validation. Invalid amount strings bypass startup checks and fail later when converting to runtime calls.</comment>

<file context>
@@ -0,0 +1,186 @@
+    return String(value);
+  }
+  if (typeof value === "string") {
+    return value;
+  }
+  throw new Error(`${fieldName} must be a decimal string, bigint, or safe integer number`);
</file context>

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