-
Notifications
You must be signed in to change notification settings - Fork 0
perf: wasm intent layer #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
conwayconstar
wants to merge
3
commits into
main
Choose a base branch
from
perf/wasm-intent-layer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ target/ | |
| node_modules/ | ||
| .direnv | ||
| wasm/pkg/ | ||
| wasm/.generated/ | ||
| .claude/settings.local.json | ||
| .claude/worktrees/ | ||
| .DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
wasm/codegen/bullet_schema/emit/startup_subpaths/calls.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| use heck::{ToLowerCamelCase, ToSnakeCase}; | ||
|
|
||
| use super::super::super::{ActionGroup, SchemaInfo}; | ||
| use super::helpers::{ | ||
| field_names_array, js_params, js_string, js_values, ordered_fields, ts_param, | ||
| }; | ||
|
|
||
| pub fn emit_calls_js(info: &SchemaInfo) -> String { | ||
| let mut out = String::new(); | ||
| out.push_str(CALLS_JS_HEADER); | ||
| out.push('\n'); | ||
|
|
||
| for group in &info.action_groups { | ||
| emit_namespace_js(&mut out, group); | ||
| out.push('\n'); | ||
| } | ||
|
|
||
| out.push_str(WARP_JS); | ||
| out | ||
| } | ||
|
|
||
| pub fn emit_calls_dts(info: &SchemaInfo) -> String { | ||
| let mut out = calls_dts_header(info); | ||
|
|
||
| for group in &info.action_groups { | ||
| emit_namespace_dts(&mut out, group); | ||
| out.push('\n'); | ||
| } | ||
|
|
||
| out.push_str(WARP_DTS); | ||
| out | ||
| } | ||
|
|
||
| fn calls_dts_header(info: &SchemaInfo) -> String { | ||
| let imports = info | ||
| .enums | ||
| .iter() | ||
| .map(|e| e.type_name.clone()) | ||
| .chain(info.structs.iter().map(|s| s.type_name.clone())) | ||
| .collect::<Vec<_>>() | ||
| .join(", "); | ||
|
|
||
| format!( | ||
| r#"// Auto-generated by wasm/build.rs - do not edit manually. | ||
| import type {{ RuntimeCallData }} from "./startup-shared.js"; | ||
| import type {{ {imports} }} from "./primitives.js"; | ||
| export type {{ JsonObject, JsonPrimitive, JsonValue, RuntimeCallData }} from "./startup-shared.js"; | ||
| export {{ isRuntimeCallData, toRuntimeCallJson }} from "./startup-shared.js"; | ||
|
|
||
| "# | ||
| ) | ||
| } | ||
|
|
||
| fn emit_namespace_js(out: &mut String, group: &ActionGroup) { | ||
| out.push_str(&format!("export class {} {{\n", group.call_message_variant)); | ||
| for variant in &group.variants { | ||
| let fields = ordered_fields(&variant.fields); | ||
| let method = variant.variant_name.to_lower_camel_case(); | ||
| let action = variant.variant_name.to_snake_case(); | ||
| let group_name = group.call_message_variant.to_snake_case(); | ||
| let params = js_params(&fields); | ||
| let names = field_names_array(&fields); | ||
| let values = js_values(&fields); | ||
|
|
||
| out.push_str(&format!(" static {method}({params}) {{\n")); | ||
| out.push_str(&format!( | ||
| " return makeExchangeCall({}, {}, {names}, [{values}]);\n", | ||
| js_string(&group_name), | ||
| js_string(&action) | ||
| )); | ||
| out.push_str(" }\n"); | ||
| } | ||
| out.push_str("}\n"); | ||
| } | ||
|
|
||
| fn emit_namespace_dts(out: &mut String, group: &ActionGroup) { | ||
| out.push_str(&format!("export declare class {} {{\n", group.call_message_variant)); | ||
| for variant in &group.variants { | ||
| let method = variant.variant_name.to_lower_camel_case(); | ||
| let params = | ||
| ordered_fields(&variant.fields).iter().map(ts_param).collect::<Vec<_>>().join(", "); | ||
|
|
||
| out.push_str(&format!(" static {method}({params}): RuntimeCallData;\n")); | ||
| } | ||
| out.push_str("}\n"); | ||
| } | ||
|
|
||
| const CALLS_JS_HEADER: &str = r#"// Auto-generated by wasm/build.rs - do not edit manually. | ||
| import { brandCall, isObject, makeFields } from "./startup-shared.js"; | ||
|
|
||
| export { isRuntimeCallData, toRuntimeCallJson } from "./startup-shared.js"; | ||
|
|
||
| function makeExchangeCall(group, action, names, values) { | ||
| return brandCall({ | ||
| exchange: { | ||
| [group]: { | ||
| [action]: makeFields(names, values), | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| "#; | ||
|
|
||
| const WARP_JS: &str = r#"function normalizeWarpAmount(value, fieldName) { | ||
| if (typeof value === "bigint") { | ||
| if (value < 0n) { | ||
| throw new Error(`${fieldName} must be a non-negative integer`); | ||
| } | ||
| return value.toString(); | ||
| } | ||
| if (typeof value === "number") { | ||
| if (!Number.isFinite(value) || value < 0 || !Number.isInteger(value)) { | ||
| throw new Error(`${fieldName} number must be a non-negative integer`); | ||
| } | ||
| if (!Number.isSafeInteger(value)) { | ||
| throw new Error(`${fieldName} number exceeds JavaScript safe integer range; pass a decimal string`); | ||
| } | ||
| return String(value); | ||
| } | ||
| if (typeof value === "string") { | ||
| return value; | ||
| } | ||
| throw new Error(`${fieldName} must be a decimal string, bigint, or safe integer number`); | ||
| } | ||
|
|
||
| function normalizeRelayer(value) { | ||
| if (value === undefined || value === null) { | ||
| return undefined; | ||
| } | ||
| if (typeof value === "string") { | ||
| return value; | ||
| } | ||
| if (isObject(value)) { | ||
| const standard = value.Standard ?? value.standard; | ||
| const vm = value.Vm ?? value.vm; | ||
| if (standard !== undefined && vm !== undefined) { | ||
| throw new Error("relayer object must include either Standard or Vm, not both"); | ||
| } | ||
| if (standard !== undefined) { | ||
| return standard; | ||
| } | ||
| if (vm !== undefined) { | ||
| return vm; | ||
| } | ||
| } | ||
| throw new Error("relayer must be a string, {Standard: string}, {Vm: string}, null, or undefined"); | ||
| } | ||
|
|
||
| export class Warp { | ||
| static transferRemote(args) { | ||
| const relayer = normalizeRelayer(args.relayer); | ||
| return brandCall({ | ||
| warp: { | ||
| transfer_remote: makeFields( | ||
| ["warp_route", "destination_domain", "recipient", "amount", "relayer", "gas_payment_limit"], | ||
| [ | ||
| args.warpRoute ?? args.warp_route, | ||
| args.destinationDomain ?? args.destination_domain, | ||
| args.recipient, | ||
| normalizeWarpAmount(args.amount, "amount"), | ||
| relayer, | ||
| normalizeWarpAmount(args.gasPaymentLimit ?? args.gas_payment_limit, "gasPaymentLimit"), | ||
| ], | ||
| ), | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| "#; | ||
|
|
||
| const WARP_DTS: &str = r#"export interface WarpTransferRemoteArgs { | ||
| warpRoute?: string; | ||
| warp_route?: string; | ||
| amount: string | number | bigint; | ||
| destinationDomain?: number; | ||
| destination_domain?: number; | ||
| gasPaymentLimit?: string | number | bigint; | ||
| gas_payment_limit?: string | number | bigint; | ||
| recipient: string; | ||
| relayer?: { Standard: string } | { standard: string } | { Vm: string } | { vm: string } | string | null; | ||
| } | ||
|
|
||
| export declare class Warp { | ||
| static transferRemote(args: WarpTransferRemoteArgs): RuntimeCallData; | ||
| } | ||
| "#; | ||
45 changes: 45 additions & 0 deletions
45
wasm/codegen/bullet_schema/emit/startup_subpaths/errors.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| pub fn emit_errors_js() -> &'static str { | ||
| ERRORS_JS | ||
| } | ||
|
|
||
| pub fn emit_errors_dts() -> &'static str { | ||
| ERRORS_DTS | ||
| } | ||
|
|
||
| const ERRORS_JS: &str = r#"// Auto-generated by wasm/build.rs - do not edit manually. | ||
| export { BulletSdkError } from "./bullet-sdk-error.js"; | ||
|
|
||
| function isObject(value) { | ||
| return typeof value === "object" && value !== null; | ||
| } | ||
|
|
||
| export function isBulletSdkError(error) { | ||
| return isObject(error) | ||
| && error.name === "BulletSdkError" | ||
| && typeof error.message === "string" | ||
| && typeof error.kind === "string" | ||
| && typeof error.retryable === "boolean"; | ||
| } | ||
|
|
||
| export function asBulletSdkError(error) { | ||
| return isBulletSdkError(error) ? error : undefined; | ||
| } | ||
| "#; | ||
|
|
||
| const ERRORS_DTS: &str = r#"// Auto-generated by wasm/build.rs - do not edit manually. | ||
| export { | ||
| BulletSdkError, | ||
| } from "./bullet-sdk-error.js"; | ||
| export type { | ||
| BulletSdkErrorDetails, | ||
| BulletSdkErrorDetailsByKind, | ||
| BulletSdkErrorKind, | ||
| BulletSdkErrorOptions, | ||
| BulletSdkErrorStatus, | ||
| JsonValue as BulletSdkJsonValue, | ||
| } from "./bullet-sdk-error.js"; | ||
| import type { BulletSdkError } from "./bullet-sdk-error.js"; | ||
|
|
||
| export declare function isBulletSdkError(error: unknown): error is BulletSdkError; | ||
| export declare function asBulletSdkError(error: unknown): BulletSdkError | undefined; | ||
| "#; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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